class SelectionBase

Same name in this branch

Base class for selection plugins provided by Entity Reference.

Hierarchy

Expanded class hierarchy of SelectionBase

File

drupal/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Derivative/SelectionBase.php, line 15
Contains \Drupal\entity_reference\Plugin\Derivative\SelectionBase.

Namespace

Drupal\entity_reference\Plugin\Derivative
View source
class SelectionBase implements DerivativeInterface {

  /**
   * Holds the list of plugin derivatives.
   *
   * @var array
   */
  protected $derivatives = array();

  /**
   * Implements DerivativeInterface::getDerivativeDefinition().
   */
  public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) {
    if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
      return $this->derivatives[$derivative_id];
    }
    $this
      ->getDerivativeDefinitions($base_plugin_definition);
    return $this->derivatives[$derivative_id];
  }

  /**
   * Implements DerivativeInterface::getDerivativeDefinitions().
   */
  public function getDerivativeDefinitions(array $base_plugin_definition) {
    $supported_entities = array(
      'comment',
      'file',
      'node',
      'taxonomy_term',
      'user',
    );
    foreach (entity_get_info() as $entity_type => $info) {
      if (!in_array($entity_type, $supported_entities)) {
        $this->derivatives[$entity_type] = $base_plugin_definition;
        $this->derivatives[$entity_type]['label'] = t('@enitty_type selection', array(
          '@entity_type' => $info['label'],
        ));
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SelectionBase::$derivatives protected property Holds the list of plugin derivatives.
SelectionBase::getDerivativeDefinition public function Implements DerivativeInterface::getDerivativeDefinition(). Overrides DerivativeInterface::getDerivativeDefinition
SelectionBase::getDerivativeDefinitions public function Implements DerivativeInterface::getDerivativeDefinitions(). Overrides DerivativeInterface::getDerivativeDefinitions