forked from markaspot/service_request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_request.module
50 lines (42 loc) · 1.26 KB
/
service_request.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @file
* Contains service_request.module.
*
* This is a content type to run an georeport v2 server.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\paragraphs\Entity\Paragraph;
/**
* Implements hook_entity_presave().
*/
function service_request_entity_presave(EntityInterface $node) {
// Add paragraph for service_requests that are created / not updated.
if ($node->bundle() == 'service_request' && !$node->id()) {
// Get some relevant config.
$config = \Drupal::configFactory()
->getEditable('markaspot_open311.settings');
// Add an intitial paragraph on post
// Status when inserting.
$status_open = array_values($config->get('status_open_start'));
// todo: put this in config.
$status_note_initial = t('The service request has been created.');
$paragraph = Paragraph::create([
'type' => 'status',
'field_status_note' => array(
"value" => $status_note_initial,
"format" => "full_html",
),
'field_status_term' => array(
"target_id" => $status_open[0],
),
]);
$paragraph->save();
$node->field_status_notes = array(
array(
'target_id' => $paragraph->id(),
'target_revision_id' => $paragraph->getRevisionId(),
),
);
}
}