Completed
Pull Request — 8.x-1.x (#126)
by Janez
02:09
created

PluginConfigFormBase::getPlugin()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
nc 1
1
<?php
2
3
/**
4
 * @file
5
 * Contains \Drupal\entity_browser\Form\PluginConfigFormBase.
6
 */
7
8
namespace Drupal\entity_browser\Form;
9
10
use Drupal\Core\Form\FormBase;
11
use Drupal\Core\Form\FormStateInterface;
12
use Drupal\entity_browser\EntityBrowserInterface;
13
14
abstract class PluginConfigFormBase extends FormBase {
15
16
  /**
17
   * {@inheritdoc}
18
   */
19
  public function buildForm(array $form, FormStateInterface $form_state) {
20
    /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
21
    $entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser'];
22
    $form = $this->getPlugin($entity_browser)->buildConfigurationForm($form, $form_state);
23
    return $form;
24
  }
25
26
  /**
27
   * {@inheritdoc}
28
   */
29
  public function validateForm(array &$form, FormStateInterface $form_state) {
30
    /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
31
    $entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser'];
32
    $this->getPlugin($entity_browser)->validateConfigurationForm($form, $form_state);
33
  }
34
35
  /**
36
   * {@inheritdoc}
37
   */
38
  public function submitForm(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)->submitConfigurationForm($form, $form_state);
42
  }
43
44
  /**
45
   * Gets plugin that form operates with.
46
   *
47
   * @return \Drupal\Core\Plugin\PluginFormInterface
48
   *   Plugin instance.
49
   */
50
  abstract public function getPlugin(EntityBrowserInterface $entity_browser);
51
52
}
53