Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
MenuDelete | |
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_delete', |
18 | enabled_by_default: TRUE, |
19 | label: new TranslatableMarkup('Delete action'), |
20 | description: new TranslatableMarkup('Provide remove action.'), |
21 | type: IslandType::Menu, |
22 | )] |
23 | class MenuDelete extends IslandPluginBase { |
24 | |
25 | /** |
26 | * {@inheritdoc} |
27 | */ |
28 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
29 | $builder_id = (string) $builder->id(); |
30 | // Attribute data-contextual-menu is important for the js mapping. |
31 | // @see assets/js/contextual_menu.js |
32 | // Urls are generated with placeholders to be replaced in the js. |
33 | $remove = $this->buildMenuItem($this->t('Remove'), 'remove'); |
34 | $remove = $this->htmxEvents->onClickDelete($remove, $builder_id, '__node_id__'); |
35 | |
36 | return [ |
37 | $this->buildMenuDivider(), |
38 | $remove, |
39 | ]; |
40 | } |
41 | |
42 | } |