Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 16 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| BackButton | |
0.00% |
0 / 22 |
|
0.00% |
0 / 16 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| build | |
0.00% |
0 / 11 |
|
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| hasButtons | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| findParentDisplayFromId | |
0.00% |
0 / 5 |
|
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 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\Core\Url; |
| 9 | use Drupal\display_builder\Attribute\Island; |
| 10 | use Drupal\display_builder\InstanceInterface; |
| 11 | use Drupal\display_builder\IslandPluginToolbarButtonConfigurationBase; |
| 12 | use Drupal\display_builder\IslandType; |
| 13 | |
| 14 | /** |
| 15 | * Help parent link island plugin implementation. |
| 16 | */ |
| 17 | #[Island( |
| 18 | id: 'back', |
| 19 | enabled_by_default: TRUE, |
| 20 | label: new TranslatableMarkup('Back'), |
| 21 | description: new TranslatableMarkup('Exit the display builder and go back to admin UI.'), |
| 22 | type: IslandType::Button, |
| 23 | )] |
| 24 | class BackButton extends IslandPluginToolbarButtonConfigurationBase { |
| 25 | |
| 26 | /** |
| 27 | * {@inheritdoc} |
| 28 | */ |
| 29 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
| 30 | $url = self::findParentDisplayFromId((string) $builder->id()); |
| 31 | |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 33 | return []; |
| 34 | } |
| 35 | |
| 36 | $button = $this->buildButton( |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 38 | 'back', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 40 | $this->t('Exit without losing any data.'), |
| 41 | ); |
| 42 | $button['#attributes']['href'] = $url->toString(); |
| 43 | |
| 44 | return $button; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * {@inheritdoc} |
| 49 | */ |
| 50 | protected function hasButtons(): array { |
| 51 | return [ |
| 52 | 'back' => [ |
| 53 | 'title' => $this->t('Back'), |
| 54 | 'default' => 'icon', |
| 55 | ], |
| 56 | ]; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Simply determine the parent display type from id. |
| 61 | * |
| 62 | * @param string $instance_id |
| 63 | * The builder instance ID. |
| 64 | * |
| 65 | * @return \Drupal\Core\Url|null |
| 66 | * The url of the instance. |
| 67 | */ |
| 68 | private static function findParentDisplayFromId(string $instance_id): ?Url { |
| 69 | // phpcs:ignore-next-line Drupal.DeprecatedFunctions.GlobalFunction |
| 70 | $providers = \Drupal::moduleHandler()->invokeAll('display_builder_provider_info'); |
| 71 | |
| 72 | foreach ($providers as $provider) { |
| 73 | if (\str_starts_with($instance_id, $provider['prefix'])) { |
| 74 | return $provider['class']::getDisplayUrlFromInstanceId($instance_id); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 29 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
| 30 | $url = self::findParentDisplayFromId((string) $builder->id()); |
| 31 | |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 33 | return []; |
| 29 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
| 30 | $url = self::findParentDisplayFromId((string) $builder->id()); |
| 31 | |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 36 | $button = $this->buildButton( |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 38 | 'back', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 40 | $this->t('Exit without losing any data.'), |
| 41 | ); |
| 42 | $button['#attributes']['href'] = $url->toString(); |
| 43 | |
| 44 | return $button; |
| 29 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
| 30 | $url = self::findParentDisplayFromId((string) $builder->id()); |
| 31 | |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 36 | $button = $this->buildButton( |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 38 | 'back', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 40 | $this->t('Exit without losing any data.'), |
| 41 | ); |
| 42 | $button['#attributes']['href'] = $url->toString(); |
| 43 | |
| 44 | return $button; |
| 29 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
| 30 | $url = self::findParentDisplayFromId((string) $builder->id()); |
| 31 | |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 36 | $button = $this->buildButton( |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 38 | 'back', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 40 | $this->t('Exit without losing any data.'), |
| 41 | ); |
| 42 | $button['#attributes']['href'] = $url->toString(); |
| 43 | |
| 44 | return $button; |
| 29 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
| 30 | $url = self::findParentDisplayFromId((string) $builder->id()); |
| 31 | |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 36 | $button = $this->buildButton( |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 37 | ($this->showLabel('back')) ? $this->t('Back') : '', |
| 38 | 'back', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 39 | $this->showIcon('back') ? 'box-arrow-up-right' : '', |
| 40 | $this->t('Exit without losing any data.'), |
| 41 | ); |
| 42 | $button['#attributes']['href'] = $url->toString(); |
| 43 | |
| 44 | return $button; |
| 29 | public function build(InstanceInterface $builder, array $data = [], array $options = []): array { |
| 30 | $url = self::findParentDisplayFromId((string) $builder->id()); |
| 31 | |
| 32 | if (!$url || !$this->isButtonEnabled('back')) { |
| 33 | return []; |
| 68 | private static function findParentDisplayFromId(string $instance_id): ?Url { |
| 69 | // phpcs:ignore-next-line Drupal.DeprecatedFunctions.GlobalFunction |
| 70 | $providers = \Drupal::moduleHandler()->invokeAll('display_builder_provider_info'); |
| 71 | |
| 72 | foreach ($providers as $provider) { |
| 72 | foreach ($providers as $provider) { |
| 73 | if (\str_starts_with($instance_id, $provider['prefix'])) { |
| 74 | return $provider['class']::getDisplayUrlFromInstanceId($instance_id); |
| 68 | private static function findParentDisplayFromId(string $instance_id): ?Url { |
| 69 | // phpcs:ignore-next-line Drupal.DeprecatedFunctions.GlobalFunction |
| 70 | $providers = \Drupal::moduleHandler()->invokeAll('display_builder_provider_info'); |
| 71 | |
| 72 | foreach ($providers as $provider) { |
| 72 | foreach ($providers as $provider) { |
| 73 | if (\str_starts_with($instance_id, $provider['prefix'])) { |
| 72 | foreach ($providers as $provider) { |
| 72 | foreach ($providers as $provider) { |
| 73 | if (\str_starts_with($instance_id, $provider['prefix'])) { |
| 74 | return $provider['class']::getDisplayUrlFromInstanceId($instance_id); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return NULL; |
| 68 | private static function findParentDisplayFromId(string $instance_id): ?Url { |
| 69 | // phpcs:ignore-next-line Drupal.DeprecatedFunctions.GlobalFunction |
| 70 | $providers = \Drupal::moduleHandler()->invokeAll('display_builder_provider_info'); |
| 71 | |
| 72 | foreach ($providers as $provider) { |
| 72 | foreach ($providers as $provider) { |
| 72 | foreach ($providers as $provider) { |
| 73 | if (\str_starts_with($instance_id, $provider['prefix'])) { |
| 74 | return $provider['class']::getDisplayUrlFromInstanceId($instance_id); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return NULL; |
| 68 | private static function findParentDisplayFromId(string $instance_id): ?Url { |
| 69 | // phpcs:ignore-next-line Drupal.DeprecatedFunctions.GlobalFunction |
| 70 | $providers = \Drupal::moduleHandler()->invokeAll('display_builder_provider_info'); |
| 71 | |
| 72 | foreach ($providers as $provider) { |
| 72 | foreach ($providers as $provider) { |
| 73 | if (\str_starts_with($instance_id, $provider['prefix'])) { |
| 74 | return $provider['class']::getDisplayUrlFromInstanceId($instance_id); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return NULL; |
| 53 | 'title' => $this->t('Back'), |
| 54 | 'default' => 'icon', |