class EntityOperations in Drupal 10
Same name in this branch
- 10 core/modules/content_moderation/src/EntityOperations.php \Drupal\content_moderation\EntityOperations
- 10 core/modules/workspaces/src/EntityOperations.php \Drupal\workspaces\EntityOperations
- 10 core/modules/views/src/Plugin/views/field/EntityOperations.php \Drupal\views\Plugin\views\field\EntityOperations
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/field/EntityOperations.php \Drupal\views\Plugin\views\field\EntityOperations
- 9 core/modules/views/src/Plugin/views/field/EntityOperations.php \Drupal\views\Plugin\views\field\EntityOperations
Renders all operations links for an entity.
Plugin annotation
@ViewsField("entity_operations");
Hierarchy
- class \Drupal\views\Plugin\views\field\EntityOperations extends \Drupal\views\Plugin\views\field\FieldPluginBase uses RedirectDestinationTrait, EntityTranslationRenderTrait
Expanded class hierarchy of EntityOperations
1 file declares its use of EntityOperations
- EntityOperationsUnitTest.php in core/
modules/ views/ tests/ src/ Unit/ Plugin/ views/ field/ EntityOperationsUnitTest.php
File
- core/
modules/ views/ src/ Plugin/ views/ field/ EntityOperations.php, line 21
Namespace
Drupal\views\Plugin\views\fieldView source
class EntityOperations extends FieldPluginBase {
use EntityTranslationRenderTrait;
use RedirectDestinationTrait;
/**
* 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 EntityOperations 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.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, EntityRepositoryInterface $entity_repository) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->languageManager = $language_manager;
$this->entityRepository = $entity_repository;
}
/**
* {@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'));
}
/**
* {@inheritdoc}
*/
public function usesGroupBy() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function defineOptions() {
$options = parent::defineOptions();
$options['destination'] = [
'default' => FALSE,
];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['destination'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include destination'),
'#description' => $this
->t('Enforce a <code>destination</code> parameter in the link to return the user to the original view upon completing the link action. Most operations include a destination by default and this setting is no longer needed.'),
'#default_value' => $this->options['destination'],
];
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$entity = $this
->getEntityTranslation($this
->getEntity($values), $values);
$operations = $this->entityTypeManager
->getListBuilder($entity
->getEntityTypeId())
->getOperations($entity);
if ($this->options['destination']) {
foreach ($operations as &$operation) {
if (!isset($operation['query'])) {
$operation['query'] = [];
}
$operation['query'] += $this
->getDestinationArray();
}
}
$build = [
'#type' => 'operations',
'#links' => $operations,
];
return $build;
}
/**
* {@inheritdoc}
*/
public function query() {
// We purposefully do not call parent::query() because we do not want the
// default query behavior for Views fields. Instead, let the entity
// translation renderer provide the correct query behavior.
if ($this->languageManager
->isMultilingual()) {
$this
->getEntityTranslationRenderer()
->query($this->query, $this->relationship);
}
}
/**
* {@inheritdoc}
*/
public function getEntityTypeId() {
return $this
->getEntityType();
}
/**
* {@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}
*/
public function clickSortable() {
return FALSE;
}
}