--- /dev/null
+<?php
+
+/**
+ * @file
+ * Provides hook implementations for Layout Builder tests.
+ */
+
+use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
+use Drupal\Core\Entity\EntityInterface;
+
+/**
+ * Implements hook_plugin_filter_TYPE__CONSUMER_alter().
+ */
+function layout_builder_test_plugin_filter_block__layout_builder_alter(array &$definitions, array $extra) {
+ // Explicitly remove the "Help" blocks from the list.
+ unset($definitions['help_block']);
+
+ // Explicitly remove the "Sticky at top of lists field_block".
+ $disallowed_fields = [
+ 'sticky',
+ ];
+
+ // Remove "Changed" field if this is the first section.
+ if ($extra['delta'] === 0) {
+ $disallowed_fields[] = 'changed';
+ }
+
+ foreach ($definitions as $plugin_id => $definition) {
+ // Field block IDs are in the form 'field_block:{entity}:{bundle}:{name}',
+ // for example 'field_block:node:article:revision_timestamp'.
+ preg_match('/field_block:.*:.*:(.*)/', $plugin_id, $parts);
+ if (isset($parts[1]) && in_array($parts[1], $disallowed_fields, TRUE)) {
+ // Unset any field blocks that match our predefined list.
+ unset($definitions[$plugin_id]);
+ }
+ }
+}
+
+/**
+ * Implements hook_entity_extra_field_info().
+ */
+function layout_builder_test_entity_extra_field_info() {
+ $extra['node']['bundle_with_section_field']['display']['layout_builder_test'] = [
+ 'label' => t('Extra label'),
+ 'description' => t('Extra description'),
+ 'weight' => 0,
+ ];
+ return $extra;
+}
+
+/**
+ * Implements hook_entity_node_view().
+ */
+function layout_builder_test_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
+ if ($display->getComponent('layout_builder_test')) {
+ $build['layout_builder_test'] = [
+ '#markup' => 'Extra, Extra read all about it.',
+ ];
+ }
+}