e7d310a6cb7f597f8162a8eefe4c965c4896040e
[yaffs-website] / web / core / modules / layout_builder / tests / modules / layout_builder_test / layout_builder_test.module
1 <?php
2
3 /**
4  * @file
5  * Provides hook implementations for Layout Builder tests.
6  */
7
8 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
9 use Drupal\Core\Entity\EntityInterface;
10
11 /**
12  * Implements hook_plugin_filter_TYPE__CONSUMER_alter().
13  */
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']);
17
18   // Explicitly remove the "Sticky at top of lists field_block".
19   $disallowed_fields = [
20     'sticky',
21   ];
22
23   // Remove "Changed" field if this is the first section.
24   if ($extra['delta'] === 0) {
25     $disallowed_fields[] = 'changed';
26   }
27
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]);
35     }
36   }
37 }
38
39 /**
40  * Implements hook_entity_extra_field_info().
41  */
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'),
46     'weight' => 0,
47   ];
48   return $extra;
49 }
50
51 /**
52  * Implements hook_entity_node_view().
53  */
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.',
58     ];
59   }
60 }