class EntityRow in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/row/EntityRow.php \Drupal\views\Plugin\views\row\EntityRow
- 9 core/modules/views/src/Plugin/views/row/EntityRow.php \Drupal\views\Plugin\views\row\EntityRow
Generic entity row plugin to provide a common base for all entity types.
Plugin annotation
@ViewsRow(
id = "entity",
deriver = "Drupal\views\Plugin\Derivative\ViewsEntityRow"
)
Hierarchy
- class \Drupal\views\Plugin\views\row\EntityRow extends \Drupal\views\Plugin\views\row\RowPluginBase uses EntityTranslationRenderTrait
Expanded class hierarchy of EntityRow
2 files declare their use of EntityRow
- NodeRow.php in core/
modules/ node/ src/ Plugin/ views/ row/ NodeRow.php - UserRow.php in core/
modules/ user/ src/ Plugin/ views/ row/ UserRow.php
File
- core/
modules/ views/ src/ Plugin/ views/ row/ EntityRow.php, line 23
Namespace
Drupal\views\Plugin\views\rowView source
class EntityRow extends RowPluginBase {
use EntityTranslationRenderTrait;
/**
* The table the entity is using for storage.
*
* @var string
*/
public $base_table;
/**
* Stores the entity type ID of the result entities.
*
* @var string
*/
protected $entityTypeId;
/**
* Contains the entity type of this row plugin instance.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $entityType;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity repository service.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a new EntityRow object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, EntityRepositoryInterface $entity_repository = NULL, EntityDisplayRepositoryInterface $entity_display_repository = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->languageManager = $language_manager;
$this->entityRepository = $entity_repository;
$this->entityDisplayRepository = $entity_display_repository;
}
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->entityTypeId = $this->definition['entity_type'];
$this->entityType = $this->entityTypeManager
->getDefinition($this->entityTypeId);
$this->base_table = $this->entityType
->getDataTable() ?: $this->entityType
->getBaseTable();
$this->base_field = $this->entityType
->getKey('id');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('language_manager'), $container
->get('entity.repository'), $container
->get('entity_display.repository'));
}
/**
* {@inheritdoc}
*/
public function getEntityTypeId() {
return $this->entityType
->id();
}
/**
* {@inheritdoc}
*/
protected function getEntityTypeManager() {
return $this->entityTypeManager;
}
/**
* {@inheritdoc}
*/
protected function getEntityRepository() {
return $this->entityRepository;
}
/**
* {@inheritdoc}
*/
protected function getLanguageManager() {
return $this->languageManager;
}
/**
* {@inheritdoc}
*/
protected function getView() {
return $this->view;
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['view_mode'] = [
'default' => 'default',
];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['view_mode'] = [
'#type' => 'select',
'#options' => $this->entityDisplayRepository
->getViewModeOptions($this->entityTypeId),
'#title' => $this
->t('View mode'),
'#default_value' => $this->options['view_mode'],
];
}
/**
* {@inheritdoc}
*/
public function summaryTitle() {
$options = $this->entityDisplayRepository
->getViewModeOptions($this->entityTypeId);
if (isset($options[$this->options['view_mode']])) {
return $options[$this->options['view_mode']];
}
else {
return $this
->t('No view mode selected');
}
}
/**
* {@inheritdoc}
*/
public function query() {
parent::query();
$this
->getEntityTranslationRenderer()
->query($this->view
->getQuery());
}
/**
* {@inheritdoc}
*/
public function preRender($result) {
parent::preRender($result);
if ($result) {
$this
->getEntityTranslationRenderer()
->preRender($result);
}
}
/**
* {@inheritdoc}
*/
public function render($row) {
return $this
->getEntityTranslationRenderer()
->render($row);
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$view_mode = $this->entityTypeManager
->getStorage('entity_view_mode')
->load($this->entityTypeId . '.' . $this->options['view_mode']);
if ($view_mode) {
$dependencies[$view_mode
->getConfigDependencyKey()][] = $view_mode
->getConfigDependencyName();
}
return $dependencies;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityRow:: |
public | property | The table the entity is using for storage. | |
EntityRow:: |
protected | property | The entity display repository. | |
EntityRow:: |
protected | property | The entity repository service. | |
EntityRow:: |
protected | property | Contains the entity type of this row plugin instance. | |
EntityRow:: |
protected | property | Stores the entity type ID of the result entities. | |
EntityRow:: |
protected | property | The entity type manager. | |
EntityRow:: |
protected | property | The language manager. | |
EntityRow:: |
public | function | ||
EntityRow:: |
public | function | ||
EntityRow:: |
public static | function | ||
EntityRow:: |
protected | function | 2 | |
EntityRow:: |
protected | function | ||
EntityRow:: |
public | function |
Returns the entity type identifier. Overrides EntityTranslationRenderTrait:: |
|
EntityRow:: |
protected | function | ||
EntityRow:: |
protected | function |
Returns the language manager. Overrides EntityTranslationRenderTrait:: |
|
EntityRow:: |
protected | function |
Returns the top object of a view. Overrides EntityTranslationRenderTrait:: |
|
EntityRow:: |
public | function | ||
EntityRow:: |
public | function | ||
EntityRow:: |
public | function | ||
EntityRow:: |
public | function | ||
EntityRow:: |
public | function | ||
EntityRow:: |
public | function | Constructs a new EntityRow object. | |
EntityTranslationRenderTrait:: |
protected | property | The renderer to be used to render the entity row. | |
EntityTranslationRenderTrait:: |
public | function | Returns the entity translation matching the configured row language. | |
EntityTranslationRenderTrait:: |
protected | function | Returns the current renderer. |