You are here

abstract class TamperPluginBase in Tamper 7

Base class for Tamper plugins.

Hierarchy

Expanded class hierarchy of TamperPluginBase

File

src/Tamper.php, line 236
Contains TamperPluginBase.

View source
abstract class TamperPluginBase implements TamperPluginInterface {

  /**
   * The plugin id.
   *
   * @var string
   */
  protected $pluginId;

  /**
   * The plugin implementation definition.
   *
   * @var TamperPluginDefinition
   */
  protected $pluginDefinition;

  /**
   * Configuration information passed into the plugin.
   *
   * @var array
   */
  protected $configuration;

  /**
   * Constructs a TamperPluginBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin id for the plugin instance.
   * @param TamperPluginDefinition $plugin_definition
   *   The plugin implementation definition.
   */
  public function __construct(array $configuration, $plugin_id, TamperPluginDefinition $plugin_definition) {
    $this->pluginId = $plugin_id;
    $this->pluginDefinition = $plugin_definition;

    // Calling setConfiguration() ensures the configuration is clean and
    // defaults are set.
    $this
      ->setConfiguration($configuration);
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginId() {
    return $this->pluginId;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginDefinition() {
    return $this->pluginDefinition;
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration($key = NULL) {
    if ($key === NULL) {
      return $this->configuration;
    }
    if (isset($this->configuration[$key])) {
      return $this->configuration[$key];
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $defaults = $this
      ->defaultConfiguration();
    $this->configuration = array_intersect_key($configuration, $defaults) + $defaults;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, array &$form_state) {

    // Validation is optional.
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, array &$form_state) {
    $this
      ->setConfiguration($form_state['values']['tamper_configuration']);
  }

  /**
   * {@inheritdoc}
   */
  public function executeMultiple(array $values) {
    foreach ($values as $delta => $value) {
      $values[$delta] = $this
        ->execute($value);
    }
    return $values;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TamperPluginBase::$configuration protected property Configuration information passed into the plugin.
TamperPluginBase::$pluginDefinition protected property The plugin implementation definition.
TamperPluginBase::$pluginId protected property The plugin id.
TamperPluginBase::executeMultiple public function Executes the plugin on multiple values. Overrides TamperPluginInterface::executeMultiple
TamperPluginBase::getConfiguration public function Returns this plugin's configuration. Overrides TamperPluginInterface::getConfiguration
TamperPluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides TamperPluginInterface::getPluginDefinition
TamperPluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides TamperPluginInterface::getPluginId
TamperPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides TamperPluginInterface::setConfiguration
TamperPluginBase::submitConfigurationForm public function Form submission handler. Overrides TamperPluginInterface::submitConfigurationForm
TamperPluginBase::validateConfigurationForm public function Form validation handler. Overrides TamperPluginInterface::validateConfigurationForm
TamperPluginBase::__construct public function Constructs a TamperPluginBase object.
TamperPluginInterface::buildConfigurationForm public function Form constructor. 1
TamperPluginInterface::defaultConfiguration public function Returns default configuration for this plugin. 1
TamperPluginInterface::execute public function Executes the plugin. 1