This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathentity_browser.install
61 lines (56 loc) · 1.95 KB
/
entity_browser.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
<?php
/**
* @file
* Update hooks for the Entity browser module.
*/
/**
* Updates submit text for existing Entity browsers.
*/
function entity_browser_update_8001() {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = \Drupal::service('config.factory');
foreach ($config_factory->listAll('entity_browser.browser') as $name) {
$entity_browser = $config_factory->getEditable($name);
if ($text = $entity_browser->get('submit_text')) {
$entity_browser->clear('submit_text');
foreach ($entity_browser->get('widgets') as $widget_uuid => $widget) {
$entity_browser->set("widgets.$widget_uuid.settings.submit_text", $text);
$entity_browser->save();
}
}
}
}
/**
* Migrates duplicated Views entity_browser_select fields.
*/
function entity_browser_update_8002() {
// Map entity data tables to base tables.
$table_map = [];
foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type_name => $entity_type) {
$base_table = $entity_type->getBaseTable();
$data_table = $entity_type->getDataTable();
if ($base_table && $data_table) {
$table_map[$data_table] = $base_table;
}
}
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('views.view.') as $view_config_name) {
$save = FALSE;
$view = $config_factory->getEditable($view_config_name);
$displays = $view->get('display');
foreach ($displays as $display_name => &$display) {
if ($display['display_options'] && isset($display['display_options']['fields'])) {
foreach ($display['display_options']['fields'] as $field_name => &$field) {
if ($field['plugin_id'] === 'entity_browser_select' && isset($table_map[$field['table']])) {
$field['table'] = $table_map[$field['table']];
$save = TRUE;
}
}
}
}
if ($save) {
$view->set('display', $displays);
$view->save(TRUE);
}
}
}