X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flayout_builder%2Flayout_builder.install;fp=web%2Fcore%2Fmodules%2Flayout_builder%2Flayout_builder.install;h=ec16a05537c43f36f592bafd3d6cc36dc6173167;hp=acb1e4fdf3d9cc6bdcf3a5e39a95e89557fe9c48;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/layout_builder/layout_builder.install b/web/core/modules/layout_builder/layout_builder.install index acb1e4fdf..ec16a0553 100644 --- a/web/core/modules/layout_builder/layout_builder.install +++ b/web/core/modules/layout_builder/layout_builder.install @@ -6,6 +6,8 @@ */ use Drupal\Core\Cache\Cache; +use Drupal\Core\Database\Database; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\layout_builder\Section; @@ -13,6 +15,8 @@ use Drupal\layout_builder\Section; * Implements hook_install(). */ function layout_builder_install() { + $display_changed = FALSE; + $displays = LayoutBuilderEntityViewDisplay::loadMultiple(); /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $displays */ foreach ($displays as $display) { @@ -20,21 +24,115 @@ function layout_builder_install() { $field_layout = $display->getThirdPartySettings('field_layout'); if (isset($field_layout['id'])) { $field_layout += ['settings' => []]; - $display->appendSection(new Section($field_layout['id'], $field_layout['settings'])); - } - - // Sort the components by weight. - $components = $display->get('content'); - uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); - foreach ($components as $name => $component) { - $display->setComponent($name, $component); + $display + ->enableLayoutBuilder() + ->appendSection(new Section($field_layout['id'], $field_layout['settings'])) + ->save(); + $display_changed = TRUE; } - $display->save(); } // Clear the rendered cache to ensure the new layout builder flow is used. // While in many cases the above change will not affect the rendered output, // the cacheability metadata will have changed and should be processed to // prepare for future changes. - Cache::invalidateTags(['rendered']); + if ($display_changed) { + Cache::invalidateTags(['rendered']); + } +} + +/** + * Enable Layout Builder for existing entity displays. + */ +function layout_builder_update_8601(&$sandbox) { + $config_factory = \Drupal::configFactory(); + + if (!isset($sandbox['count'])) { + $sandbox['ids'] = $config_factory->listAll('core.entity_view_display.'); + $sandbox['count'] = count($sandbox['ids']); + } + + $ids = array_splice($sandbox['ids'], 0, 50); + foreach ($ids as $id) { + $display = $config_factory->getEditable($id); + if ($display->get('third_party_settings.layout_builder')) { + $display + ->set('third_party_settings.layout_builder.enabled', TRUE) + ->save(); + } + } + + $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count']; +} + +/** + * Implements hook_schema(). + */ +function layout_builder_schema() { + $schema['inline_block_usage'] = [ + 'description' => 'Track where a block_content entity is used.', + 'fields' => [ + 'block_content_id' => [ + 'description' => 'The block_content entity ID.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ], + 'layout_entity_type' => [ + 'description' => 'The entity type of the parent entity.', + 'type' => 'varchar_ascii', + 'length' => EntityTypeInterface::ID_MAX_LENGTH, + 'not null' => FALSE, + 'default' => '', + ], + 'layout_entity_id' => [ + 'description' => 'The ID of the parent entity.', + 'type' => 'varchar_ascii', + 'length' => 128, + 'not null' => FALSE, + 'default' => 0, + ], + ], + 'primary key' => ['block_content_id'], + 'indexes' => [ + 'type_id' => ['layout_entity_type', 'layout_entity_id'], + ], + ]; + return $schema; +} + +/** + * Create the 'inline_block_usage' table. + */ +function layout_builder_update_8602() { + $inline_block_usage = [ + 'description' => 'Track where a block_content entity is used.', + 'fields' => [ + 'block_content_id' => [ + 'description' => 'The block_content entity ID.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ], + 'layout_entity_type' => [ + 'description' => 'The entity type of the parent entity.', + 'type' => 'varchar_ascii', + 'length' => EntityTypeInterface::ID_MAX_LENGTH, + 'not null' => FALSE, + 'default' => '', + ], + 'layout_entity_id' => [ + 'description' => 'The ID of the parent entity.', + 'type' => 'varchar_ascii', + 'length' => 128, + 'not null' => FALSE, + 'default' => 0, + ], + ], + 'primary key' => ['block_content_id'], + 'indexes' => [ + 'type_id' => ['layout_entity_type', 'layout_entity_id'], + ], + ]; + Database::getConnection()->schema()->createTable('inline_block_usage', $inline_block_usage); }