validateConfigurationForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\entity_browser;
4
use Drupal\Core\Form\FormStateInterface;
5
6
/**
7
 * Provides base form methods for configurable plugins entity browser.
8
 */
9
trait PluginConfigurationFormTrait {
10
11
  /**
12
   * Implements PluginFormInterface::buildConfigurationForm().
13
   */
14
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_state is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
15
    return $form;
16
  }
17
18
  /**
19
   * Implements PluginFormInterface::validateConfigurationForm().
20
   */
21
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $form_state is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
  }
23
24
  /**
25
   * Implements PluginFormInterface::submitConfigurationForm().
26
   *
27
   * This is the default implementation for the most common cases where the form
28
   * element names match keys in configuration array. Plugins can override this
29
   * if they need more complex logic.
30
   */
31
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    $values = $form_state->getValues();
33
34
    if ($this instanceof WidgetInterface) {
35
      $values = $values['table'][$this->uuid()]['form'];
36
    }
37
38
    if (!empty($values)) {
39
      foreach ($values as $key => $value) {
40
        if (array_key_exists($key, $this->configuration)) {
41
          $this->configuration[$key] = $value;
0 ignored issues
show
Bug introduced by
The property configuration does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
        }
43
      }
44
    }
45
  }
46
47
}
48