You are here

trait PluginConfigurationFormTrait in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 src/PluginConfigurationFormTrait.php \Drupal\entity_browser\PluginConfigurationFormTrait

Provides base form methods for configurable plugins entity browser.

Hierarchy

File

src/PluginConfigurationFormTrait.php, line 10

Namespace

Drupal\entity_browser
View source
trait PluginConfigurationFormTrait {

  /**
   * Implements PluginFormInterface::buildConfigurationForm().
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    return $form;
  }

  /**
   * Implements PluginFormInterface::validateConfigurationForm().
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * Implements PluginFormInterface::submitConfigurationForm().
   *
   * This is the default implementation for the most common cases where the form
   * element names match keys in configuration array. Plugins can override this
   * if they need more complex logic.
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    if ($this instanceof WidgetInterface) {
      $values = $values['table'][$this
        ->uuid()]['form'];
    }
    if (!empty($values)) {
      foreach ($values as $key => $value) {
        if (array_key_exists($key, $this->configuration)) {
          $this->configuration[$key] = $value;
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginConfigurationFormTrait::buildConfigurationForm public function Implements PluginFormInterface::buildConfigurationForm(). 5
PluginConfigurationFormTrait::submitConfigurationForm public function Implements PluginFormInterface::submitConfigurationForm(). 3
PluginConfigurationFormTrait::validateConfigurationForm public function Implements PluginFormInterface::validateConfigurationForm(). 2