class EntityDerivative

Provides a resource plugin definition for every entity type.

Hierarchy

Expanded class hierarchy of EntityDerivative

File

drupal/core/modules/rest/lib/Drupal/rest/Plugin/Derivative/EntityDerivative.php, line 15
Definition of Drupal\rest\Plugin\Derivative\EntityDerivative.

Namespace

Drupal\rest\Plugin\Derivative
View source
class EntityDerivative implements DerivativeInterface {

  /**
   * List of derivative definitions.
   *
   * @var array
   */
  protected $derivatives;

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

  /**
   * Implements DerivativeInterface::getDerivativeDefinitions().
   */
  public function getDerivativeDefinitions(array $base_plugin_definition) {
    if (!isset($this->derivatives)) {

      // Add in the default plugin configuration and the resource type.
      foreach (entity_get_info() as $entity_type => $entity_info) {
        $this->derivatives[$entity_type] = array(
          'id' => 'entity:' . $entity_type,
          'entity_type' => $entity_type,
          'label' => $entity_info['label'],
        );
        $this->derivatives[$entity_type] += $base_plugin_definition;
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityDerivative::$derivatives protected property List of derivative definitions.
EntityDerivative::getDerivativeDefinition public function Implements DerivativeInterface::getDerivativeDefinition(). Overrides DerivativeInterface::getDerivativeDefinition
EntityDerivative::getDerivativeDefinitions public function Implements DerivativeInterface::getDerivativeDefinitions(). Overrides DerivativeInterface::getDerivativeDefinitions