entity_agree-2.0.x-dev/src/AgreementHandlerPluginBase.php
src/AgreementHandlerPluginBase.php
<?php namespace Drupal\entity_agree; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; /** * Base class for agreement handler plugins. */ abstract class AgreementHandlerPluginBase extends PluginBase implements AgreementHandlerInterface { /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->setConfiguration($configuration); } /** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { return $form; } /** * {@inheritdoc} */ public function defaultConfiguration() { return []; } /** * {@inheritdoc} */ public function getConfiguration() { return $this->configuration; } /** * {@inheritdoc} */ public function getCategory() { return $this->getPluginDefinition()['category']; } /** * {@inheritdoc} */ public function getLabel() { return $this->getPluginDefinition()['label']; } /** * {@inheritdoc} */ public function setConfiguration(array $configuration) { $this->configuration = $configuration + $this->defaultConfiguration(); } /** * {@inheritdoc} */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { // Set submitted form values into plugin config. Override as needed to // perform adjustments to data/structure of configuration. $this->setConfiguration($form_state->getValue($form['#parents'])); } /** * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { // No op, override in child classes as needed. } }