-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwmbert.install
83 lines (69 loc) · 2.54 KB
/
wmbert.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
79
80
81
82
83
<?php
use Drupal\field\Entity\FieldConfig;
/**
* Move the label_formatter & disable_parent_entity_selection settings
* from the form display to the field handler_settings
*/
function wmbert_update_8001(): void
{
$formDisplays = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->loadMultiple();
$fieldManager = \Drupal::getContainer()
->get('entity_field.manager');
$settingKeys = [
'disable_parent_entity_selection',
'label_formatter',
];
foreach ($formDisplays as $formDisplay) {
$content = $formDisplay->get('content');
foreach ($content as $fieldName => &$fieldDisplay) {
foreach ($settingKeys as $settingKey) {
if (!isset($fieldDisplay['settings'][$settingKey])) {
continue;
}
/** @var FieldConfig[] $fieldDefinitions */
$fieldDefinitions = $fieldManager->getFieldDefinitions(
$formDisplay->getTargetEntityTypeId(),
$formDisplay->getTargetBundle()
);
$fieldDefinition = $fieldDefinitions[$fieldName];
$handlerSettings = $fieldDefinition->getSetting('handler_settings');
if (!empty($handlerSettings[$settingKey])) {
continue;
}
$handlerSettings[$settingKey] = $fieldDisplay['settings'][$settingKey];
$fieldDefinition->setSetting('handler_settings', $handlerSettings);
$fieldDefinition->save();
unset($fieldDisplay['settings'][$settingKey]);
}
}
$formDisplay->set('content', $content);
$formDisplay->save();
}
}
/**
* Set the default value for the new published_only option
*/
function wmbert_update_8002(): void
{
$storage = \Drupal::entityTypeManager()
->getStorage('field_config');
$configNames = $storage->getQuery()
->condition('field_type', 'entity_reference')
->accessCheck(false)
->execute();
/** @var FieldConfig $config */
foreach ($storage->loadMultiple($configNames) as $config) {
if (strpos($config->getSetting('handler'), 'wmbert') !== 0) {
continue;
}
$handlerSettings = $config->getSetting('handler_settings');
if (isset($handlerSettings['published_only'])) {
continue;
}
$handlerSettings['published_only'] = 0;
$config->setSetting('handler_settings', $handlerSettings);
$config->save();
}
}