Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 14 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| IslandFormBase | |
0.00% |
0 / 24 |
|
0.00% |
0 / 14 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFormId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| buildForm | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| validateForm | |
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| submitForm | |
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| getPlugin | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getIslandManager | |
0.00% |
0 / 1 |
|
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\Form; |
| 6 | |
| 7 | use Drupal\Core\Form\FormBase; |
| 8 | use Drupal\Core\Form\FormStateInterface; |
| 9 | use Drupal\display_builder\Island\IslandInterface; |
| 10 | use Drupal\display_builder\Island\IslandPluginManagerInterface; |
| 11 | use Drupal\display_builder\Island\IslandWithFormInterface; |
| 12 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 13 | |
| 14 | /** |
| 15 | * Provides a display builder form for island plugin. |
| 16 | */ |
| 17 | final class IslandFormBase extends FormBase { |
| 18 | |
| 19 | /** |
| 20 | * Constructs a new IslandFormBase. |
| 21 | * |
| 22 | * @param \Drupal\display_builder\Island\IslandPluginManagerInterface|null $islandManager |
| 23 | * The island plugin manager. NULL when form is rebuilt from cache without |
| 24 | * going through the container — getIslandManager() handles the fallback. |
| 25 | */ |
| 26 | public function __construct( |
| 27 | private ?IslandPluginManagerInterface $islandManager = NULL, |
| 28 | ) {} |
| 29 | |
| 30 | /** |
| 31 | * {@inheritdoc} |
| 32 | */ |
| 33 | public static function create(ContainerInterface $container): static { |
| 34 | return new self( |
| 35 | $container->get('plugin.manager.db_island'), |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * {@inheritdoc} |
| 41 | */ |
| 42 | public function getFormId(): string { |
| 43 | return 'display_builder_island'; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * {@inheritdoc} |
| 48 | */ |
| 49 | public function buildForm(array $form, FormStateInterface $form_state): array { |
| 50 | $island_args = $form_state->getBuildInfo()['args'][0]; |
| 51 | $plugin = $this->getPlugin($island_args); |
| 52 | |
| 53 | if (!$plugin instanceof IslandWithFormInterface) { |
| 54 | return $form; |
| 55 | } |
| 56 | $plugin->setBuilderId($island_args['builder_id']); |
| 57 | $plugin->buildForm($form, $form_state); |
| 58 | |
| 59 | return $form; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * {@inheritdoc} |
| 64 | */ |
| 65 | public function validateForm(array &$form, FormStateInterface $form_state): void { |
| 66 | $island_args = $form_state->getBuildInfo()['args'][0]; |
| 67 | $plugin = $this->getPlugin($island_args); |
| 68 | |
| 69 | if (!$plugin instanceof IslandWithFormInterface) { |
| 70 | return; |
| 71 | } |
| 72 | $plugin->validateForm($form, $form_state); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * {@inheritdoc} |
| 77 | */ |
| 78 | public function submitForm(array &$form, FormStateInterface $form_state): void { |
| 79 | $island_args = $form_state->getBuildInfo()['args'][0]; |
| 80 | $plugin = $this->getPlugin($island_args); |
| 81 | |
| 82 | if (!$plugin instanceof IslandWithFormInterface) { |
| 83 | return; |
| 84 | } |
| 85 | $plugin->submitForm($form, $form_state); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Gets an island plugin instance from form args. |
| 90 | * |
| 91 | * @param array $args |
| 92 | * Arguments from form_state which allow to load plugin. |
| 93 | * |
| 94 | * @return \Drupal\display_builder\Island\IslandInterface |
| 95 | * The Island plugin. |
| 96 | */ |
| 97 | protected function getPlugin(array $args): IslandInterface { |
| 98 | return $this->getIslandManager()->createInstance($args['island_id'], $args['instance']); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Gets the island plugin manager, falling back to the container. |
| 103 | * |
| 104 | * FormBase subclasses may be rebuilt from cache without going through |
| 105 | * create(), leaving injected properties uninitialized. |
| 106 | * |
| 107 | * @return \Drupal\display_builder\Island\IslandPluginManagerInterface |
| 108 | * The island plugin manager. |
| 109 | * |
| 110 | * @phpcs:disable DrupalPractice.Objects.GlobalDrupal.GlobalDrupal |
| 111 | */ |
| 112 | private function getIslandManager(): IslandPluginManagerInterface { |
| 113 | // @phpstan-ignore nullCoalesce.property |
| 114 | return $this->islandManager ??= \Drupal::service('plugin.manager.db_island'); |
| 115 | } |
| 116 | |
| 117 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 27 | private ?IslandPluginManagerInterface $islandManager = NULL, |
| 28 | ) {} |
| 49 | public function buildForm(array $form, FormStateInterface $form_state): array { |
| 50 | $island_args = $form_state->getBuildInfo()['args'][0]; |
| 51 | $plugin = $this->getPlugin($island_args); |
| 52 | |
| 53 | if (!$plugin instanceof IslandWithFormInterface) { |
| 54 | return $form; |
| 56 | $plugin->setBuilderId($island_args['builder_id']); |
| 57 | $plugin->buildForm($form, $form_state); |
| 58 | |
| 59 | return $form; |
| 60 | } |
| 33 | public static function create(ContainerInterface $container): static { |
| 34 | return new self( |
| 35 | $container->get('plugin.manager.db_island'), |
| 36 | ); |
| 37 | } |
| 43 | return 'display_builder_island'; |
| 44 | } |
| 114 | return $this->islandManager ??= \Drupal::service('plugin.manager.db_island'); |
| 115 | } |
| 97 | protected function getPlugin(array $args): IslandInterface { |
| 98 | return $this->getIslandManager()->createInstance($args['island_id'], $args['instance']); |
| 99 | } |
| 78 | public function submitForm(array &$form, FormStateInterface $form_state): void { |
| 79 | $island_args = $form_state->getBuildInfo()['args'][0]; |
| 80 | $plugin = $this->getPlugin($island_args); |
| 81 | |
| 82 | if (!$plugin instanceof IslandWithFormInterface) { |
| 83 | return; |
| 85 | $plugin->submitForm($form, $form_state); |
| 86 | } |
| 65 | public function validateForm(array &$form, FormStateInterface $form_state): void { |
| 66 | $island_args = $form_state->getBuildInfo()['args'][0]; |
| 67 | $plugin = $this->getPlugin($island_args); |
| 68 | |
| 69 | if (!$plugin instanceof IslandWithFormInterface) { |
| 70 | return; |
| 72 | $plugin->validateForm($form, $form_state); |
| 73 | } |