Mercurial > hg > isophonics-drupal-site
comparison core/modules/layout_builder/layout_builder.install @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
4 * @file | 4 * @file |
5 * Contains install and update functions for Layout Builder. | 5 * Contains install and update functions for Layout Builder. |
6 */ | 6 */ |
7 | 7 |
8 use Drupal\Core\Cache\Cache; | 8 use Drupal\Core\Cache\Cache; |
9 use Drupal\Core\Database\Database; | |
10 use Drupal\Core\Entity\EntityTypeInterface; | |
9 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; | 11 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; |
10 use Drupal\layout_builder\Section; | 12 use Drupal\layout_builder\Section; |
11 | 13 |
12 /** | 14 /** |
13 * Implements hook_install(). | 15 * Implements hook_install(). |
14 */ | 16 */ |
15 function layout_builder_install() { | 17 function layout_builder_install() { |
18 $display_changed = FALSE; | |
19 | |
16 $displays = LayoutBuilderEntityViewDisplay::loadMultiple(); | 20 $displays = LayoutBuilderEntityViewDisplay::loadMultiple(); |
17 /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $displays */ | 21 /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $displays */ |
18 foreach ($displays as $display) { | 22 foreach ($displays as $display) { |
19 // Create the first section from any existing Field Layout settings. | 23 // Create the first section from any existing Field Layout settings. |
20 $field_layout = $display->getThirdPartySettings('field_layout'); | 24 $field_layout = $display->getThirdPartySettings('field_layout'); |
21 if (isset($field_layout['id'])) { | 25 if (isset($field_layout['id'])) { |
22 $field_layout += ['settings' => []]; | 26 $field_layout += ['settings' => []]; |
23 $display->appendSection(new Section($field_layout['id'], $field_layout['settings'])); | 27 $display |
28 ->enableLayoutBuilder() | |
29 ->appendSection(new Section($field_layout['id'], $field_layout['settings'])) | |
30 ->save(); | |
31 $display_changed = TRUE; | |
24 } | 32 } |
25 | |
26 // Sort the components by weight. | |
27 $components = $display->get('content'); | |
28 uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); | |
29 foreach ($components as $name => $component) { | |
30 $display->setComponent($name, $component); | |
31 } | |
32 $display->save(); | |
33 } | 33 } |
34 | 34 |
35 // Clear the rendered cache to ensure the new layout builder flow is used. | 35 // Clear the rendered cache to ensure the new layout builder flow is used. |
36 // While in many cases the above change will not affect the rendered output, | 36 // While in many cases the above change will not affect the rendered output, |
37 // the cacheability metadata will have changed and should be processed to | 37 // the cacheability metadata will have changed and should be processed to |
38 // prepare for future changes. | 38 // prepare for future changes. |
39 Cache::invalidateTags(['rendered']); | 39 if ($display_changed) { |
40 Cache::invalidateTags(['rendered']); | |
41 } | |
40 } | 42 } |
43 | |
44 /** | |
45 * Enable Layout Builder for existing entity displays. | |
46 */ | |
47 function layout_builder_update_8601(&$sandbox) { | |
48 $config_factory = \Drupal::configFactory(); | |
49 | |
50 if (!isset($sandbox['count'])) { | |
51 $sandbox['ids'] = $config_factory->listAll('core.entity_view_display.'); | |
52 $sandbox['count'] = count($sandbox['ids']); | |
53 } | |
54 | |
55 $ids = array_splice($sandbox['ids'], 0, 50); | |
56 foreach ($ids as $id) { | |
57 $display = $config_factory->getEditable($id); | |
58 if ($display->get('third_party_settings.layout_builder')) { | |
59 $display | |
60 ->set('third_party_settings.layout_builder.enabled', TRUE) | |
61 ->save(); | |
62 } | |
63 } | |
64 | |
65 $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count']; | |
66 } | |
67 | |
68 /** | |
69 * Implements hook_schema(). | |
70 */ | |
71 function layout_builder_schema() { | |
72 $schema['inline_block_usage'] = [ | |
73 'description' => 'Track where a block_content entity is used.', | |
74 'fields' => [ | |
75 'block_content_id' => [ | |
76 'description' => 'The block_content entity ID.', | |
77 'type' => 'int', | |
78 'unsigned' => TRUE, | |
79 'not null' => TRUE, | |
80 ], | |
81 'layout_entity_type' => [ | |
82 'description' => 'The entity type of the parent entity.', | |
83 'type' => 'varchar_ascii', | |
84 'length' => EntityTypeInterface::ID_MAX_LENGTH, | |
85 'not null' => FALSE, | |
86 'default' => '', | |
87 ], | |
88 'layout_entity_id' => [ | |
89 'description' => 'The ID of the parent entity.', | |
90 'type' => 'varchar_ascii', | |
91 'length' => 128, | |
92 'not null' => FALSE, | |
93 'default' => 0, | |
94 ], | |
95 ], | |
96 'primary key' => ['block_content_id'], | |
97 'indexes' => [ | |
98 'type_id' => ['layout_entity_type', 'layout_entity_id'], | |
99 ], | |
100 ]; | |
101 return $schema; | |
102 } | |
103 | |
104 /** | |
105 * Create the 'inline_block_usage' table. | |
106 */ | |
107 function layout_builder_update_8602() { | |
108 $inline_block_usage = [ | |
109 'description' => 'Track where a block_content entity is used.', | |
110 'fields' => [ | |
111 'block_content_id' => [ | |
112 'description' => 'The block_content entity ID.', | |
113 'type' => 'int', | |
114 'unsigned' => TRUE, | |
115 'not null' => TRUE, | |
116 ], | |
117 'layout_entity_type' => [ | |
118 'description' => 'The entity type of the parent entity.', | |
119 'type' => 'varchar_ascii', | |
120 'length' => EntityTypeInterface::ID_MAX_LENGTH, | |
121 'not null' => FALSE, | |
122 'default' => '', | |
123 ], | |
124 'layout_entity_id' => [ | |
125 'description' => 'The ID of the parent entity.', | |
126 'type' => 'varchar_ascii', | |
127 'length' => 128, | |
128 'not null' => FALSE, | |
129 'default' => 0, | |
130 ], | |
131 ], | |
132 'primary key' => ['block_content_id'], | |
133 'indexes' => [ | |
134 'type_id' => ['layout_entity_type', 'layout_entity_id'], | |
135 ], | |
136 ]; | |
137 Database::getConnection()->schema()->createTable('inline_block_usage', $inline_block_usage); | |
138 } |