Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PageLayoutHook | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
entityOperationAlter | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
displayBuilderProviderInfo | |
0.00% |
0 / 7 |
|
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\Entity\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 page'), |
41 | 'url' => PageLayout::getDisplayUrlFromInstanceId($id), |
42 | 'weight' => 10, |
43 | ]; |
44 | } |
45 | } |
46 | |
47 | /** |
48 | * Implements hook_display_builder_provider_info(). |
49 | * |
50 | * @return array |
51 | * An associative array of display builder providers. |
52 | */ |
53 | #[Hook('display_builder_provider_info')] |
54 | public function displayBuilderProviderInfo(): array { |
55 | return [ |
56 | 'page_layout' => [ |
57 | 'label' => new TranslatableMarkup('Page layout'), |
58 | 'class' => PageLayout::class, |
59 | 'prefix' => PageLayout::getPrefix(), |
60 | ], |
61 | ]; |
62 | } |
63 | |
64 | } |