This repository has been archived by the owner on Jun 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
synpanel.install
78 lines (69 loc) · 2.5 KB
/
synpanel.install
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* @file
* Contains install and update hooks.
*/
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Implements hook_install().
*/
function synpanel_install() {
$entity_manager = \Drupal::entityManager();
$entity_type = $entity_manager->getDefinition('contact_message');
// Recreate the original entity type definition, in order to notify the
// manager of what changed. The change of storage backend will trigger
// schema installation.
// @see synpanel_test_entity_type_alter()
$original = clone $entity_type;
$original->setStorageClass('Drupal\Core\Entity\ContentEntityNullStorage');
$entity_manager->onEntityTypeUpdate($entity_type, $original);
_synpanel_ensure_fields();
}
/**
* Make sure the fields are added.
*/
function synpanel_update_8001() {
_synpanel_ensure_fields();
}
/**
* Ensure fields are added.
*/
function _synpanel_ensure_fields() {
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
$field_manager = \Drupal::service('entity_field.manager');
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
foreach (['piwik', 'formurl'] as $field_name) {
$field_definition = $field_manager->getFieldStorageDefinitions('contact_message')[$field_name];
$entity_definition_update_manager->installFieldStorageDefinition($field_name, 'contact_message', 'synpanel', $field_definition);
}
}
/**
* Defines fields for the user id and ip address, for the contact messages.
*/
function synpanel_update_8002() {
$storage_definition = BaseFieldDefinition::create('string')
->setLabel(t('Piwik ID'))
->setDescription(t('Piwik ID of the submitter.'))
->setDefaultValueCallback('synpanel_contact_message_default_piwik');
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('piwik', 'contact_message', 'synpanel', $storage_definition);
}
/**
* Make sure the fields are added.
*/
function synpanel_update_8003() {
_synpanel_ensure_fields();
}
/**
* Defines fields for the user id and ip address, for the contact messages.
*/
function synpanel_update_8004() {
$storage_definition = BaseFieldDefinition::create('string')
->setLabel(t('Form URL'))
->setDescription(t('Form URL of the submission.'))
->setDefaultValueCallback('synpanel_contact_message_default_formurl');
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('formurl', 'contact_message', 'synpanel', $storage_definition);
}