Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PageLayoutHook | |
0.00% |
0 / 15 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| entityOperationAlter | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| preprocessHtml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\display_builder_page_layout\Hook; |
| 6 | |
| 7 | use Drupal\Core\Entity\EntityInterface; |
| 8 | use Drupal\Core\Hook\Attribute\Hook; |
| 9 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
| 10 | use Drupal\display_builder\InstanceInterface; |
| 11 | use Drupal\display_builder_page_layout\Plugin\display_builder\Buildable\PageLayout; |
| 12 | |
| 13 | /** |
| 14 | * Hook implementations for the display_builder_page_layout module. |
| 15 | */ |
| 16 | class PageLayoutHook { |
| 17 | |
| 18 | /** |
| 19 | * Implements hook_entity_operation_alter(). |
| 20 | * |
| 21 | * @param array $operations |
| 22 | * An associative array of operations. |
| 23 | * @param \Drupal\Core\Entity\EntityInterface $entity |
| 24 | * The entity for which the operations are being altered. |
| 25 | */ |
| 26 | #[Hook('entity_operation_alter')] |
| 27 | public function entityOperationAlter(array &$operations, EntityInterface $entity): void { |
| 28 | if (!$entity instanceof InstanceInterface) { |
| 29 | return; |
| 30 | } |
| 31 | $id = (string) $entity->id(); |
| 32 | |
| 33 | if (\str_starts_with($id, PageLayout::getPrefix())) { |
| 34 | $operations['build'] = [ |
| 35 | 'title' => new TranslatableMarkup('Build display'), |
| 36 | 'url' => PageLayout::getUrlFromInstanceId($id), |
| 37 | 'weight' => -1, |
| 38 | ]; |
| 39 | $operations['edit'] = [ |
| 40 | 'title' => new TranslatableMarkup('Edit display'), |
| 41 | 'url' => PageLayout::getDisplayUrlFromInstanceId($id), |
| 42 | 'weight' => 10, |
| 43 | ]; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Preprocess theme variables for HTML templates. |
| 49 | * |
| 50 | * @param array $variables |
| 51 | * The variables array (modify in place). |
| 52 | * |
| 53 | * @see \Drupal\display_builder_page_layout\Plugin\DisplayVariant\FullPageBuilderPageVariant |
| 54 | */ |
| 55 | #[Hook('preprocess_html')] |
| 56 | public function preprocessHtml(array &$variables): void { |
| 57 | unset($variables['page']['content']['page_title']); |
| 58 | } |
| 59 | |
| 60 | } |