class 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 15
Namespace
Drupal\layout_builder_test\HookView source
class LayoutBuilderTestEntityHooks {
/**
* 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.',
];
}
}
/**
* 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,
];
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(). |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.