5 * Provides hook implementations for Layout Builder tests.
8 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
9 use Drupal\Core\Entity\EntityInterface;
12 * Implements hook_plugin_filter_TYPE__CONSUMER_alter().
14 function layout_builder_test_plugin_filter_block__layout_builder_alter(array &$definitions, array $extra) {
15 // Explicitly remove the "Help" blocks from the list.
16 unset($definitions['help_block']);
18 // Explicitly remove the "Sticky at top of lists field_block".
19 $disallowed_fields = [
23 // Remove "Changed" field if this is the first section.
24 if ($extra['delta'] === 0) {
25 $disallowed_fields[] = 'changed';
28 foreach ($definitions as $plugin_id => $definition) {
29 // Field block IDs are in the form 'field_block:{entity}:{bundle}:{name}',
30 // for example 'field_block:node:article:revision_timestamp'.
31 preg_match('/field_block:.*:.*:(.*)/', $plugin_id, $parts);
32 if (isset($parts[1]) && in_array($parts[1], $disallowed_fields, TRUE)) {
33 // Unset any field blocks that match our predefined list.
34 unset($definitions[$plugin_id]);
40 * Implements hook_entity_extra_field_info().
42 function layout_builder_test_entity_extra_field_info() {
43 $extra['node']['bundle_with_section_field']['display']['layout_builder_test'] = [
44 'label' => t('Extra label'),
45 'description' => t('Extra description'),
52 * Implements hook_entity_node_view().
54 function layout_builder_test_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
55 if ($display->getComponent('layout_builder_test')) {
56 $build['layout_builder_test'] = [
57 '#markup' => 'Extra, Extra read all about it.',