function EntityListBuilder::getDefaultOperations
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/EntityListBuilder.php \Drupal\Core\Entity\EntityListBuilder::getDefaultOperations()
- 8.9.x core/lib/Drupal/Core/Entity/EntityListBuilder.php \Drupal\Core\Entity\EntityListBuilder::getDefaultOperations()
- 10 core/lib/Drupal/Core/Entity/EntityListBuilder.php \Drupal\Core\Entity\EntityListBuilder::getDefaultOperations()
Gets this list's default operations.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity the operations are for.
Return value
array The array structure is identical to the return value of self::getOperations().
1 call to EntityListBuilder::getDefaultOperations()
- EntityListBuilder::getOperations in core/
lib/ Drupal/ Core/ Entity/ EntityListBuilder.php - Provides an array of information to build a list of operation links.
3 methods override EntityListBuilder::getDefaultOperations()
- ConfigEntityListBuilder::getDefaultOperations in core/
lib/ Drupal/ Core/ Config/ Entity/ ConfigEntityListBuilder.php - Gets this list's default operations.
- MenuLinkListBuilder::getDefaultOperations in core/
modules/ menu_link_content/ src/ MenuLinkListBuilder.php - Gets this list's default operations.
- WorkspaceListBuilder::getDefaultOperations in core/
modules/ workspaces/ src/ WorkspaceListBuilder.php - Gets this list's default operations.
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityListBuilder.php, line 150
Class
- EntityListBuilder
- Defines a generic implementation to build a listing of entities.
Namespace
Drupal\Core\EntityCode
protected function getDefaultOperations(EntityInterface $entity) {
$operations = [];
if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) {
$edit_url = $this->ensureDestination($entity->toUrl('edit-form'));
if (!empty($entity->label())) {
$label = $this->t('Edit @entity_label', [
'@entity_label' => $entity->label(),
]);
}
else {
$label = $this->t('Edit @entity_bundle @entity_id', [
'@entity_bundle' => $entity->bundle(),
'@entity_id' => $entity->id(),
]);
}
$attributes = $edit_url->getOption('attributes') ?: [];
$attributes += [
'aria-label' => $label,
];
$edit_url->setOption('attributes', $attributes);
$operations['edit'] = [
'title' => $this->t('Edit'),
'weight' => 10,
'url' => $edit_url,
];
}
if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) {
$delete_url = $this->ensureDestination($entity->toUrl('delete-form'));
if (!empty($entity->label())) {
$label = $this->t('Delete @entity_label', [
'@entity_label' => $entity->label(),
]);
}
else {
$label = $this->t('Delete @entity_bundle @entity_id', [
'@entity_bundle' => $entity->bundle(),
'@entity_id' => $entity->id(),
]);
}
$attributes = $delete_url->getOption('attributes') ?: [];
$attributes += [
'aria-label' => $label,
];
$delete_url->setOption('attributes', $attributes);
$operations['delete'] = [
'title' => $this->t('Delete'),
'weight' => 100,
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 880,
]),
],
'url' => $delete_url,
];
}
return $operations;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.