class LayoutBuilderTestEntityHooks
Same name and namespace in other branches
- 11.x core/modules/layout_builder/tests/modules/layout_builder_test/src/Hook/LayoutBuilderTestEntityHooks.php \Drupal\layout_builder_test\Hook\LayoutBuilderTestEntityHooks
Entity hook implementations for layout_builder_test.
Hierarchy
- class \Drupal\layout_builder_test\Hook\LayoutBuilderTestEntityHooks
Expanded class hierarchy of LayoutBuilderTestEntityHooks
File
-
core/
modules/ layout_builder/ tests/ modules/ layout_builder_test/ src/ Hook/ LayoutBuilderTestEntityHooks.php, line 17
Namespace
Drupal\layout_builder_test\HookView source
class LayoutBuilderTestEntityHooks {
public function __construct(#[Autowire(service: 'keyvalue')] protected readonly KeyValueFactoryInterface $keyValueFactory) {
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
public function nodeView(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.',
];
}
if ($display->getComponent('layout_builder_test_empty')) {
$build['layout_builder_test_empty'] = [
'#cache' => [
'tags' => [
'test_extra_fields_empty',
],
],
];
$render = $this->keyValueFactory
->get('test_extra_fields_empty')
->get('render_extra_field', FALSE);
if ($render) {
$build['layout_builder_test_empty'][] = [
'#type' => 'markup',
'#markup' => 'This extra field is visible because it is not empty.',
];
}
}
}
/**
* Implements hook_entity_extra_field_info().
*/
public function entityExtraFieldInfo() : array {
$extra['node']['bundle_with_section_field']['display']['layout_builder_test'] = [
'label' => 'Extra label',
'description' => 'Extra description',
'weight' => 0,
];
$extra['node']['bundle_with_section_field']['display']['layout_builder_test_2'] = [
'label' => 'Extra Field 2',
'description' => 'Extra Field 2 description',
'weight' => 0,
'visible' => FALSE,
];
$extra['node']['bundle_with_section_field']['display']['layout_builder_test_empty'] = [
'label' => 'Extra Field (empty)',
'description' => 'Extra Field (empty) description',
'weight' => 0,
];
return $extra;
}
/**
* Implements hook_entity_form_display_alter().
*/
public function layoutBuilderEntityFormDisplayAlter(EntityFormDisplayInterface $form_display, array $context) : void {
if ($context['form_mode'] === 'layout_builder') {
$form_display->setComponent('status', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
],
]);
}
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| LayoutBuilderTestEntityHooks::entityExtraFieldInfo | public | function | Implements hook_entity_extra_field_info(). |
| LayoutBuilderTestEntityHooks::layoutBuilderEntityFormDisplayAlter | public | function | Implements hook_entity_form_display_alter(). |
| LayoutBuilderTestEntityHooks::nodeView | public | function | Implements hook_ENTITY_TYPE_view(). |
| LayoutBuilderTestEntityHooks::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.