You are here

abstract class PluginBase in Views (for Drupal 7) 8.3

Hierarchy

Expanded class hierarchy of PluginBase

15 files declare their use of PluginBase
AccessPluginBase.php in lib/Drupal/views/Plugin/views/access/AccessPluginBase.php
Definition of Drupal\views\Plugin\views\access\AccessPluginBase.
AreaPluginBase.php in lib/Drupal/views/Plugin/views/area/AreaPluginBase.php
Definition of Drupal\views\Plugin\views\area\AreaPluginBase.
ArgumentDefaultPluginBase.php in lib/Drupal/views/Plugin/views/argument_default/ArgumentDefaultPluginBase.php
Definition of Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase.
ArgumentPluginBase.php in lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php
Definition of Drupal\views\Plugin\views\argument\ArgumentPluginBase.
ArgumentValidatorPluginBase.php in lib/Drupal/views/Plugin/views/argument_validator/ArgumentValidatorPluginBase.php
Definition of Drupal\views\Plugin\views\argument_validator\ArgumentValidatorPluginBase.

... See full list

File

lib/Drupal/views/Plugin/views/PluginBase.php, line 13
Definition of Drupal\views\Plugin\views\PluginBase.

Namespace

Drupal\views\Plugin\views
View source
abstract class PluginBase extends ComponentPluginBase {

  /**
   * Options for this plugin will be held here.
   *
   * @var array
   */
  public $options = array();

  /**
   * The top object of a view.
   *
   * @var Drupal\views\ViewExecutable
   */
  public $view = NULL;

  /**
   * The display object this plugin is for.
   *
   * For display plugins this is empty.
   *
   * @todo find a better description
   *
   * @var Drupal\views\Plugin\views\display\DisplayPluginBase
   */
  public $displayHandler;

  /**
   * Plugins's definition
   *
   * @var array
   */
  public $definition;

  /**
   * Denotes whether the plugin has an additional options form.
   *
   * @var bool
   */
  protected $usesOptions = FALSE;

  /**
   * Constructs a Plugin object.
   */
  public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) {
    parent::__construct($configuration, $plugin_id, $discovery);
    $this->definition = $this->discovery
      ->getDefinition($plugin_id) + $configuration;
  }

  /**
   * Information about options for all kinds of purposes will be held here.
   * @code
   * 'option_name' => array(
   *  - 'default' => default value,
   *  - 'translatable' => (optional) TRUE/FALSE (wrap in t() on export if true),
   *  - 'contains' => (optional) array of items this contains, with its own
   *      defaults, etc. If contains is set, the default will be ignored and
   *      assumed to be array().
   *  - 'bool' => (optional) TRUE/FALSE Is the value a boolean value. This will
   *      change the export format to TRUE/FALSE instead of 1/0.
   *  ),
   *
   * @return array
   *   Returns the options of this handler/plugin.
   */
  protected function defineOptions() {
    return array();
  }
  protected function setOptionDefaults(&$storage, $options, $level = 0) {
    foreach ($options as $option => $definition) {
      if (isset($definition['contains']) && is_array($definition['contains'])) {
        $storage[$option] = array();
        $this
          ->setOptionDefaults($storage[$option], $definition['contains'], $level++);
      }
      elseif (!empty($definition['translatable']) && !empty($definition['default'])) {
        $storage[$option] = t($definition['default']);
      }
      else {
        $storage[$option] = isset($definition['default']) ? $definition['default'] : NULL;
      }
    }
  }

  /**
   * Unpack options over our existing defaults, drilling down into arrays
   * so that defaults don't get totally blown away.
   */
  public function unpackOptions(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE) {
    if ($check && !is_array($options)) {
      return;
    }
    if (!isset($definition)) {
      $definition = $this
        ->defineOptions();
    }
    foreach ($options as $key => $value) {
      if (is_array($value)) {

        // Ignore arrays with no definition.
        if (!$all && empty($definition[$key])) {
          continue;
        }
        if (!isset($storage[$key]) || !is_array($storage[$key])) {
          $storage[$key] = array();
        }

        // If we're just unpacking our known options, and we're dropping an
        // unknown array (as might happen for a dependent plugin fields) go
        // ahead and drop that in.
        if (!$all && isset($definition[$key]) && !isset($definition[$key]['contains'])) {
          $storage[$key] = $value;
          continue;
        }
        $this
          ->unpackOptions($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE);
      }
      else {
        if ($all || !empty($definition[$key])) {
          $storage[$key] = $value;
        }
      }
    }
  }

  /**
   * Clears a plugin.
   */
  public function destroy() {
    unset($this->view, $this->display, $this->query);
  }

  /**
   * Init will be called after construct, when the plugin is attached to a
   * view and a display.
   */

  /**
   * Provide a form to edit options for this plugin.
   */
  public function buildOptionsForm(&$form, &$form_state) {

    // Some form elements belong in a fieldset for presentation, but can't
    // be moved into one because of the form_state['values'] hierarchy. Those
    // elements can add a #fieldset => 'fieldset_name' property, and they'll
    // be moved to their fieldset during pre_render.
    $form['#pre_render'][] = 'views_ui_pre_render_add_fieldset_markup';
  }

  /**
   * Validate the options form.
   */
  public function validateOptionsForm(&$form, &$form_state) {
  }

  /**
   * Handle any special handling on the validate form.
   */
  public function submitOptionsForm(&$form, &$form_state) {
  }

  /**
   * Add anything to the query that we might need to.
   */
  public function query() {
  }

  /**
   * Provide a full list of possible theme templates used by this style.
   */
  public function themeFunctions() {
    return views_theme_functions($this->definition['theme'], $this->view, $this->view->display_handler->display);
  }

  /**
   * Provide a list of additional theme functions for the theme information page
   */
  public function additionalThemeFunctions() {
    $funcs = array();
    if (!empty($this->definition['additional themes'])) {
      foreach ($this->definition['additional themes'] as $theme => $type) {
        $funcs[] = views_theme_functions($theme, $this->view, $this->view->display_handler->display);
      }
    }
    return $funcs;
  }

  /**
   * Validate that the plugin is correct and can be saved.
   *
   * @return
   *   An array of error strings to tell the user what is wrong with this
   *   plugin.
   */
  public function validate() {
    return array();
  }

  /**
   * Returns the summary of the settings in the display.
   */
  public function summaryTitle() {
    return t('Settings');
  }

  /**
   * Return the human readable name of the display.
   *
   * This appears on the ui beside each plugin and beside the settings link.
   */
  public function pluginTitle() {
    if (isset($this->definition['short_title'])) {
      return check_plain($this->definition['short_title']);
    }
    return check_plain($this->definition['title']);
  }

  /**
   * Returns the usesOptions property.
   */
  public function usesOptions() {
    return $this->usesOptions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$definition public property Plugins's definition
PluginBase::$displayHandler public property The display object this plugin is for.
PluginBase::$options public property Options for this plugin will be held here.
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::$usesOptions protected property Denotes whether the plugin has an additional options form. 8
PluginBase::$view public property The top object of a view. 1
PluginBase::additionalThemeFunctions public function Provide a list of additional theme functions for the theme information page
PluginBase::buildOptionsForm public function Provide a form to edit options for this plugin. 14
PluginBase::defineOptions protected function Information about options for all kinds of purposes will be held here. @code 'option_name' => array( 13
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::destroy public function Clears a plugin. 2
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::pluginTitle public function Return the human readable name of the display.
PluginBase::query public function Add anything to the query that we might need to. 13
PluginBase::setOptionDefaults protected function
PluginBase::submitOptionsForm public function Handle any special handling on the validate form. 10
PluginBase::summaryTitle public function Returns the summary of the settings in the display. 6
PluginBase::themeFunctions public function Provide a full list of possible theme templates used by this style. 1
PluginBase::unpackOptions public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
PluginBase::usesOptions public function Returns the usesOptions property. 8
PluginBase::validate public function Validate that the plugin is correct and can be saved. 4
PluginBase::validateOptionsForm public function Validate the options form. 11
PluginBase::__construct public function Constructs a Plugin object. Overrides PluginBase::__construct 2