abstract class PluginUIBase

Provides defaults for creating user interfaces for plugins of a given type.

@todo This class needs more documetation and/or

Hierarchy

Expanded class hierarchy of PluginUIBase

See also

references.

1 file declares its use of PluginUIBase
BlockPluginUI.php in drupal/core/modules/block/lib/Drupal/block/Plugin/PluginUI/BlockPluginUI.php

File

drupal/core/modules/system/lib/Drupal/system/Plugin/PluginUIBase.php, line 18
Contains \Drupal\system\Plugin\PluginUIBase.

Namespace

Drupal\system\Plugin
View source
abstract class PluginUIBase extends PluginBase implements PluginUIInterface {

  /**
   * Implements \Drupal\system\Plugin\PluginUIInterface::form().
   */
  public function form($form, &$form_state) {
    $plugin_definition = $this
      ->getPluginDefinition();

    // @todo Find out how to let the manager be injected into the class.
    if (class_exists($plugin_definition['manager'])) {
      $manager = new $plugin_definition['manager']();
    }
    else {
      $manager = drupal_container()
        ->get($plugin_definition['manager']);
    }
    $plugins = $manager
      ->getDefinitions();
    $rows = array();
    foreach ($plugins as $plugin_id => $display_plugin_definition) {
      $rows[] = $this
        ->row($plugin_id, $display_plugin_definition);
    }
    $form['plugins'] = array(
      '#theme' => 'table',
      '#header' => $this
        ->tableHeader(),
      '#rows' => $rows,
    );
    return $form;
  }

  /**
   * Implements \Drupal\system\Plugin\PluginUIInterface::formValidate().
   */
  public function formValidate($form, &$form_state) {
  }

  /**
   * Implements \Drupal\system\Plugin\PluginUIInterface::formSumbit().
   */
  public function formSubmit($form, &$form_state) {
  }

  /**
   * Checks access for plugins of this type.
   *
   * @return bool
   *   Returns TRUE if plugins of this type can be accessed.
   */
  public function access() {
    $definition = $this
      ->getPluginDefinition();
    return call_user_func_array($definition['access_callback'], $definition['access_arguments']);
  }

  /**
   * Displays a plugin row for configuring plugins in the user interface.
   *
   * @param string $display_plugin_id
   *   The ID of the specific plugin definition being passed to us.
   * @param array $display_plugin_definition
   *   The plugin definition associated with the passed $plugin_id.
   *
   * @return array
   *   An array that represents a table row in the final user interface output.
   */
  public function row($display_plugin_id, array $display_plugin_definition) {
    $plugin_definition = $this
      ->getPluginDefinition();
    return array(
      $display_plugin_definition['title'],
      l($plugin_definition['link_title'], $plugin_definition['config_path'] . '/' . $display_plugin_id),
    );
  }

  /**
   * Provides a theme_table compatible array of headers.
   *
   * @return array
   *   A theme_table compatible array of headers.
   */
  public function tableHeader() {
    return array(
      t('Title'),
      t('Operations'),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. 17
PluginUIBase::access public function Checks access for plugins of this type. 1
PluginUIBase::form public function Implements \Drupal\system\Plugin\PluginUIInterface::form(). Overrides PluginUIInterface::form 1
PluginUIBase::formSubmit public function Implements \Drupal\system\Plugin\PluginUIInterface::formSumbit(). Overrides PluginUIInterface::formSubmit 1
PluginUIBase::formValidate public function Implements \Drupal\system\Plugin\PluginUIInterface::formValidate(). Overrides PluginUIInterface::formValidate 1
PluginUIBase::row public function Displays a plugin row for configuring plugins in the user interface. 1
PluginUIBase::tableHeader public function Provides a theme_table compatible array of headers. 1