layout_builder_test.module

Same filename and directory in other branches
  1. 9 core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module
  2. 8.9.x core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module
  3. 10 core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module

File

core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module

View source
<?php


/**
 * @file
 * Provides hook implementations for Layout Builder tests.
 */

declare (strict_types=1);
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;

/**
 * Implements hook_ENTITY_TYPE_view().
 */
function layout_builder_test_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) : void {
  if ($display->getComponent('layout_builder_test')) {
    $build['layout_builder_test'] = [
      '#markup' => 'Extra, Extra read all about it.',
    ];
  }
  if ($display->getComponent('layout_builder_test_2')) {
    $build['layout_builder_test_2'] = [
      '#markup' => 'Extra Field 2 is hidden by default.',
    ];
  }
}

/**
 * Implements hook_preprocess_HOOK() for one-column layout template.
 */
function layout_builder_test_preprocess_layout__onecol(&$vars) : void {
  if (!empty($vars['content']['#entity'])) {
    $vars['content']['content'][\Drupal::service('uuid')->generate()] = [
      '#type' => 'markup',
      '#markup' => sprintf('Yes, I can access the %s', $vars['content']['#entity']->label()),
    ];
  }
}

/**
 * Implements hook_preprocess_HOOK() for two-column layout template.
 */
function layout_builder_test_preprocess_layout__twocol_section(&$vars) : void {
  if (!empty($vars['content']['#entity'])) {
    $vars['content']['first'][\Drupal::service('uuid')->generate()] = [
      '#type' => 'markup',
      '#markup' => sprintf('Yes, I can access the entity %s in two column', $vars['content']['#entity']->label()),
    ];
  }
}

Functions

Title Deprecated Summary
layout_builder_test_node_view Implements hook_ENTITY_TYPE_view().
layout_builder_test_preprocess_layout__onecol Implements hook_preprocess_HOOK() for one-column layout template.
layout_builder_test_preprocess_layout__twocol_section Implements hook_preprocess_HOOK() for two-column layout template.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.