Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Menu | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| build | |
0.00% |
0 / 10 |
|
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\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', |
| 18 | label: new TranslatableMarkup('Main menu items'), |
| 19 | description: new TranslatableMarkup('Copy, paste and duplicate.'), |
| 20 | type: IslandType::Menu, |
| 21 | )] |
| 22 | class Menu 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 | $duplicate = $this->buildMenuItem($this->t('Duplicate'), 'duplicate'); |
| 33 | $duplicate = $this->htmxEvents->onClickDuplicate($duplicate, $builder_id, '__node_id__', '__parent_id__', '__slot_id__', '__slot_position__'); |
| 34 | |
| 35 | $paste = $this->buildMenuItem($this->t('Paste'), 'paste'); |
| 36 | $paste = $this->htmxEvents->onClickPaste($paste, $builder_id, '__node_id__', '__parent_id__', '__slot_id__', '__slot_position__'); |
| 37 | |
| 38 | return [ |
| 39 | $this->buildMenuItem($this->t('Copy'), 'copy'), |
| 40 | $paste, |
| 41 | $duplicate, |
| 42 | ]; |
| 43 | } |
| 44 | |
| 45 | } |