Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DisplayBuilderViewsHook | |
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_views\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_views\Plugin\views\display_extender\DisplayExtender; |
12 | |
13 | /** |
14 | * Hook implementations for the display_builder_views module. |
15 | */ |
16 | class DisplayBuilderViewsHook { |
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 | |
32 | $id = (string) $entity->id(); |
33 | |
34 | if (\str_starts_with($id, DisplayExtender::getPrefix())) { |
35 | $operations['build'] = [ |
36 | 'title' => new TranslatableMarkup('Build display'), |
37 | 'url' => DisplayExtender::getUrlFromInstanceId($id), |
38 | 'weight' => -1, |
39 | ]; |
40 | $operations['edit'] = [ |
41 | 'title' => new TranslatableMarkup('Edit view'), |
42 | 'url' => DisplayExtender::getDisplayUrlFromInstanceId($id), |
43 | 'weight' => 10, |
44 | ]; |
45 | } |
46 | } |
47 | |
48 | /** |
49 | * Implements hook_display_builder_provider_info(). |
50 | * |
51 | * @return array |
52 | * An associative array of display builder providers. |
53 | */ |
54 | #[Hook('display_builder_provider_info')] |
55 | public function displayBuilderProviderInfo(): array { |
56 | return [ |
57 | 'views' => [ |
58 | 'label' => new TranslatableMarkup('Views'), |
59 | 'class' => DisplayExtender::class, |
60 | 'prefix' => DisplayExtender::getPrefix(), |
61 | ], |
62 | ]; |
63 | } |
64 | |
65 | } |