PluginConfigFormBase::submitForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\entity_browser\Form;
4
5
use Drupal\Core\Form\FormBase;
6
use Drupal\Core\Form\FormStateInterface;
7
use Drupal\Core\Render\Element;
8
use Drupal\entity_browser\EntityBrowserInterface;
9
10
/**
11
 * Base class for steps in entity browser form wizard.
12
 */
13
abstract class PluginConfigFormBase extends FormBase {
14
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function buildForm(array $form, FormStateInterface $form_state) {
19
    /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
20
    $entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser'];
21
    $form = $this->getPlugin($entity_browser)->buildConfigurationForm($form, $form_state);
22
23
    $fields = Element::children($form);
24
    if (empty($fields)) {
25
      $form['no_options'] = [
26
        '#prefix' => '<p>',
27
        '#suffix' => '</p>',
28
        '#markup' => $this->t('This plugin has no configuration options.'),
29
      ];
30
    }
31
32
    return $form;
33
  }
34
35
  /**
36
   * {@inheritdoc}
37
   */
38
  public function validateForm(array &$form, FormStateInterface $form_state) {
39
    /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
40
    $entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser'];
41
    $this->getPlugin($entity_browser)->validateConfigurationForm($form, $form_state);
42
  }
43
44
  /**
45
   * {@inheritdoc}
46
   */
47
  public function submitForm(array &$form, FormStateInterface $form_state) {
48
    /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
49
    $entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser'];
50
    $this->getPlugin($entity_browser)->submitConfigurationForm($form, $form_state);
51
  }
52
53
  /**
54
   * Gets plugin that form operates with.
55
   *
56
   * @return \Drupal\Core\Plugin\PluginFormInterface|\Drupal\Component\Plugin\PluginInspectionInterface
57
   *   Plugin instance.
58
   */
59
  abstract public function getPlugin(EntityBrowserInterface $entity_browser);
60
61
}
62