Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 7 |
|
0.00% |
0 / 7 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ConfirmViewsBuilderDeleteForm | |
0.00% |
0 / 18 |
|
0.00% |
0 / 7 |
|
0.00% |
0 / 7 |
|
0.00% |
0 / 7 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| buildForm | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCancelUrl | |
0.00% |
0 / 1 |
|
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 | |||
| getQuestion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| submitForm | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| unsetDisplayBuilder | |
0.00% |
0 / 7 |
|
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_views\Form; |
| 6 | |
| 7 | use Drupal\Core\DependencyInjection\AutowireTrait; |
| 8 | use Drupal\Core\Entity\EntityTypeManagerInterface; |
| 9 | use Drupal\Core\Form\ConfirmFormBase; |
| 10 | use Drupal\Core\Form\FormStateInterface; |
| 11 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
| 12 | use Drupal\Core\Url; |
| 13 | use Drupal\display_builder_views\Plugin\views\display_extender\DisplayExtender; |
| 14 | |
| 15 | /** |
| 16 | * Confirmation form to confirm deletion of display builder instance. |
| 17 | */ |
| 18 | class ConfirmViewsBuilderDeleteForm extends ConfirmFormBase { |
| 19 | |
| 20 | use AutowireTrait; |
| 21 | |
| 22 | /** |
| 23 | * Display builder id to delete. |
| 24 | */ |
| 25 | private ?string $builderId; |
| 26 | |
| 27 | public function __construct( |
| 28 | private readonly EntityTypeManagerInterface $entityTypeManager, |
| 29 | ) {} |
| 30 | |
| 31 | /** |
| 32 | * {@inheritdoc} |
| 33 | */ |
| 34 | public function buildForm(array $form, FormStateInterface $form_state, ?string $builder_id = NULL): array { |
| 35 | $this->builderId = $builder_id; |
| 36 | |
| 37 | return parent::buildForm($form, $form_state); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * {@inheritdoc} |
| 42 | */ |
| 43 | public function getCancelUrl(): Url { |
| 44 | return new Url('display_builder_views.views.collection'); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * {@inheritdoc} |
| 49 | */ |
| 50 | public function getFormId(): string { |
| 51 | return 'confirm_display_builder_views_delete_form'; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * {@inheritdoc} |
| 56 | */ |
| 57 | public function getQuestion(): TranslatableMarkup { |
| 58 | return $this->t('Do you want to delete %id?', ['%id' => $this->builderId]); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * {@inheritdoc} |
| 63 | */ |
| 64 | public function submitForm(array &$form, FormStateInterface $form_state): void { |
| 65 | $storage = $this->entityTypeManager->getStorage('display_builder_instance'); |
| 66 | $instance = $storage->load($this->builderId); |
| 67 | $storage->delete([$instance]); |
| 68 | $this->unsetDisplayBuilder(); |
| 69 | $form_state->setRedirectUrl(new Url('display_builder_views.views.collection')); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Unset display builder. |
| 74 | */ |
| 75 | protected function unsetDisplayBuilder(): void { |
| 76 | $view_id = DisplayExtender::checkInstanceId($this->builderId)['view']; |
| 77 | $display_id = DisplayExtender::checkInstanceId($this->builderId)['display']; |
| 78 | $view = $this->entityTypeManager->getStorage('view')->load($view_id); |
| 79 | // It is risky to alter a View like that. We need to be careful to not |
| 80 | // break the storage integrity, but we didn't find a better way. |
| 81 | $displays = $view->get('display'); |
| 82 | $displays[$display_id]['display_options']['display_extenders']['display_builder']['display_builder'] = ''; |
| 83 | $view->set('display', $displays); |
| 84 | $view->save(); |
| 85 | } |
| 86 | |
| 87 | } |
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.
| 27 | public function __construct( |
| 28 | private readonly EntityTypeManagerInterface $entityTypeManager, |
| 29 | ) {} |
| 34 | public function buildForm(array $form, FormStateInterface $form_state, ?string $builder_id = NULL): array { |
| 35 | $this->builderId = $builder_id; |
| 36 | |
| 37 | return parent::buildForm($form, $form_state); |
| 44 | return new Url('display_builder_views.views.collection'); |
| 51 | return 'confirm_display_builder_views_delete_form'; |
| 58 | return $this->t('Do you want to delete %id?', ['%id' => $this->builderId]); |
| 64 | public function submitForm(array &$form, FormStateInterface $form_state): void { |
| 65 | $storage = $this->entityTypeManager->getStorage('display_builder_instance'); |
| 66 | $instance = $storage->load($this->builderId); |
| 67 | $storage->delete([$instance]); |
| 68 | $this->unsetDisplayBuilder(); |
| 69 | $form_state->setRedirectUrl(new Url('display_builder_views.views.collection')); |
| 70 | } |
| 76 | $view_id = DisplayExtender::checkInstanceId($this->builderId)['view']; |
| 77 | $display_id = DisplayExtender::checkInstanceId($this->builderId)['display']; |
| 78 | $view = $this->entityTypeManager->getStorage('view')->load($view_id); |
| 79 | // It is risky to alter a View like that. We need to be careful to not |
| 80 | // break the storage integrity, but we didn't find a better way. |
| 81 | $displays = $view->get('display'); |
| 82 | $displays[$display_id]['display_options']['display_extenders']['display_builder']['display_builder'] = ''; |
| 83 | $view->set('display', $displays); |
| 84 | $view->save(); |
| 85 | } |