Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
IslandConfigurationFormTrait
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 validateConfigurationForm
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 submitConfigurationForm
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\display_builder;
6
7use Drupal\Component\Plugin\ConfigurableInterface;
8use Drupal\Core\Form\FormStateInterface;
9
10/**
11 * Add methods to make plugin configuration forms.
12 */
13trait IslandConfigurationFormTrait {
14
15  /**
16   * Validate the Island configuration.
17   *
18   * @param array $form
19   *   The form.
20   * @param \Drupal\Core\Form\FormStateInterface $form_state
21   *   The form state.
22   */
23  public function validateConfigurationForm(array &$form, FormStateInterface $form_state): void {}
24
25  /**
26   * Submit the island configuration.
27   *
28   * @param array $form
29   *   The form.
30   * @param \Drupal\Core\Form\FormStateInterface $form_state
31   *   The form state.
32   */
33  public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
34    $values = $form_state->getValues();
35    $configuration = [];
36
37    foreach ($values as $key => $value) {
38      if (($key === 'exclude' || $key === 'status') && \is_array($value)) {
39        // Remove unchecked values.
40        $value = \array_filter($value);
41      }
42      $configuration[$key] = $value;
43    }
44
45    if ($this instanceof ConfigurableInterface) {
46      $this->setConfiguration($configuration);
47    }
48  }
49
50}