class ViewsEntityRow

Same name and namespace in other branches
  1. 11.x core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php \Drupal\views\Plugin\Derivative\ViewsEntityRow
  2. 10 core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php \Drupal\views\Plugin\Derivative\ViewsEntityRow
  3. 9 core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php \Drupal\views\Plugin\Derivative\ViewsEntityRow
  4. 8.9.x core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php \Drupal\views\Plugin\Derivative\ViewsEntityRow

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

Hierarchy

Expanded class hierarchy of ViewsEntityRow

See also

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

Related topics

1 file declares its use of ViewsEntityRow
EntityRow.php in core/modules/views/src/Plugin/views/row/EntityRow.php

File

core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php, line 18

Namespace

Drupal\views\Plugin\Derivative
View source
class ViewsEntityRow implements ContainerDeriverInterface {
  use StringTranslationTrait;
  
  /**
   * Stores all entity row plugin information.
   *
   * @var array
   */
  protected $derivatives = [];
  
  /**
   * Constructs a ViewsEntityRow object.
   *
   * @param string $basePluginId
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\views\ViewsData $viewsData
   *   The views data service.
   */
  public function __construct(protected $basePluginId, protected EntityTypeManagerInterface $entityTypeManager, protected ViewsData $viewsData) {
  }
  
  /**
   * {@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' => 'entity:' . $entity_type_id,
          'provider' => 'views',
          'title' => $this->t('@label view mode', [
            '@label' => $entity_type->getLabel(),
          ]),
          'help' => $this->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

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1
ViewsEntityRow::$derivatives protected property Stores all entity row plugin information.
ViewsEntityRow::create public static function Overrides ContainerDeriverInterface::create
ViewsEntityRow::getDerivativeDefinition public function Overrides DeriverInterface::getDerivativeDefinition
ViewsEntityRow::getDerivativeDefinitions public function Overrides DeriverInterface::getDerivativeDefinitions
ViewsEntityRow::__construct public function Constructs a ViewsEntityRow object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.