Newer
Older

Lee Rowlands
committed
<?php
/**
* @file
* Contains install and update functions for Layout Builder.
*/
use Drupal\Core\Cache\Cache;

Angie Byron
committed
use Drupal\Core\Entity\EntityTypeInterface;

Lee Rowlands
committed
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\layout_builder\Section;
/**
* Implements hook_install().
*/
function layout_builder_install(): void {
$display_changed = FALSE;

Lee Rowlands
committed
$displays = LayoutBuilderEntityViewDisplay::loadMultiple();
/** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $displays */
foreach ($displays as $display) {
// Create the first section from any existing Field Layout settings.
$field_layout = $display->getThirdPartySettings('field_layout');
if (isset($field_layout['id'])) {
$field_layout += ['settings' => []];
$display
->enableLayoutBuilder()
->appendSection(new Section($field_layout['id'], $field_layout['settings']))
->save();
$display_changed = TRUE;

Lee Rowlands
committed
}
}
// 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.
if ($display_changed) {
Cache::invalidateTags(['rendered']);
}
}

Angie Byron
committed
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
/**
* 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;
}
/**
* Implements hook_update_last_removed().

Angie Byron
committed
*/
function layout_builder_update_last_removed(): int {
return 8602;