function TestPrepareLayout::onAfterPrepareLayout
Same name in other branches
- 10 core/modules/layout_builder/tests/modules/layout_builder_element_test/src/EventSubscriber/TestPrepareLayout.php \Drupal\layout_builder_element_test\EventSubscriber\TestPrepareLayout::onAfterPrepareLayout()
- 11.x core/modules/layout_builder/tests/modules/layout_builder_element_test/src/EventSubscriber/TestPrepareLayout.php \Drupal\layout_builder_element_test\EventSubscriber\TestPrepareLayout::onAfterPrepareLayout()
Subscriber to test acting after the LB subscriber.
Parameters
\Drupal\layout_builder\Event\PrepareLayoutEvent $event: The prepare layout event.
File
-
core/
modules/ layout_builder/ tests/ modules/ layout_builder_element_test/ src/ EventSubscriber/ TestPrepareLayout.php, line 101
Class
- TestPrepareLayout
- Provides an event subscriber for testing section storage alteration.
Namespace
Drupal\layout_builder_element_test\EventSubscriberCode
public function onAfterPrepareLayout(PrepareLayoutEvent $event) {
$section_storage = $event->getSectionStorage();
$context = $section_storage->getContextValues();
if (!empty($context['entity'])) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $context['entity'];
// Node 1, 2, or 3: Append a block to the layout.
if (in_array($entity->id(), [
'1',
'2',
'3',
])) {
$section = new Section('layout_onecol');
$section->appendComponent(new SectionComponent('fake-uuid', 'content', [
'id' => 'static_block_two',
'label' => 'Test second static block title',
'label_display' => 'visible',
'provider' => 'fake_provider',
]));
$section_storage->appendSection($section);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.