You are here

class DsEntityRow in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/DsEntityRow.php \Drupal\ds\Plugin\Derivative\DsEntityRow
  2. 8.3 src/Plugin/Derivative/DsEntityRow.php \Drupal\ds\Plugin\Derivative\DsEntityRow

Provides DS views row plugin definitions for all non-special entity types.

Hierarchy

Expanded class hierarchy of DsEntityRow

See also

\Drupal\ds\Plugin\views\row\EntityRow

File

src/Plugin/Derivative/DsEntityRow.php, line 17

Namespace

Drupal\ds\Plugin\Derivative
View source
class DsEntityRow implements ContainerDeriverInterface {

  /**
   * Stores all entity row plugin information.
   *
   * @var array
   */
  protected $derivatives = [];

  /**
   * The base plugin ID that the derivative is for.
   *
   * @var string
   */
  protected $basePluginId;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The views data service.
   *
   * @var \Drupal\views\ViewsData
   */
  protected $viewsData;

  /**
   * Constructs a DsEntityRow object.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity manager.
   * @param \Drupal\views\ViewsData $views_data
   *   The views data service.
   */
  public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, ViewsData $views_data) {
    $this->basePluginId = $base_plugin_id;
    $this->entityTypeManager = $entity_type_manager;
    $this->viewsData = $views_data;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($base_plugin_id, $container
      ->get('entity_type.manager'), $container
      ->get('views.views_data'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinition($derivative_id, $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];
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {

      // Just add support for entity types which have a views integration.
      if (($base_table = $entity_type
        ->getBaseTable()) && $this->viewsData
        ->get($base_table) && $this->entityTypeManager
        ->hasHandler($entity_type_id, 'view_builder')) {
        $this->derivatives[$entity_type_id] = [
          'id' => 'ds_entity:' . $entity_type_id,
          'provider' => 'ds',
          'title' => 'Display Suite: ' . $entity_type
            ->getLabel(),
          'help' => t('Display the @label', [
            '@label' => $entity_type
              ->getLabel(),
          ]),
          'base' => [
            $entity_type
              ->getDataTable() ?: $entity_type
              ->getBaseTable(),
          ],
          'entity_type' => $entity_type_id,
          'display_types' => [
            'normal',
          ],
          'class' => $base_plugin_definition['class'],
        ];
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DsEntityRow::$basePluginId protected property The base plugin ID that the derivative is for.
DsEntityRow::$derivatives protected property Stores all entity row plugin information.
DsEntityRow::$entityTypeManager protected property The entity manager.
DsEntityRow::$viewsData protected property The views data service.
DsEntityRow::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
DsEntityRow::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
DsEntityRow::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface::getDerivativeDefinitions
DsEntityRow::__construct public function Constructs a DsEntityRow object.