Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
MenuPreset | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
build | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Drupal\display_builder\Plugin\display_builder\Island; |
6 | |
7 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
8 | use Drupal\display_builder\Attribute\Island; |
9 | use Drupal\display_builder\InstanceInterface; |
10 | use Drupal\display_builder\IslandPluginBase; |
11 | use Drupal\display_builder\IslandType; |
12 | |
13 | /** |
14 | * Menu island plugin implementation. |
15 | */ |
16 | #[Island( |
17 | id: 'menu_preset', |
18 | label: new TranslatableMarkup('Preset actions'), |
19 | description: new TranslatableMarkup('Provide preset actions.'), |
20 | type: IslandType::Menu, |
21 | )] |
22 | class MenuPreset extends IslandPluginBase { |
23 | |
24 | /** |
25 | * {@inheritdoc} |
26 | */ |
27 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
28 | $builder_id = (string) $builder->id(); |
29 | // Attribute data-contextual-menu is important for the js mapping. |
30 | // @see assets/js/contextual_menu.js |
31 | // Urls are generated with placeholders to be replaced in the js. |
32 | $save_preset = $this->buildMenuItem($this->t('Save as preset'), 'save_preset'); |
33 | $save_preset = $this->htmxEvents->onClickSavePreset($save_preset, $builder_id, '__node_id__', $this->t('Name of preset')); |
34 | |
35 | return [ |
36 | $this->buildMenuDivider(), |
37 | $save_preset, |
38 | ]; |
39 | } |
40 | |
41 | } |