function EntityTestHooks::entityOperationAlter
Implements hook_entity_operation_alter().
File
-
core/
modules/ system/ tests/ modules/ entity_test/ src/ Hook/ EntityTestHooks.php, line 381
Class
- EntityTestHooks
- Hook implementations for entity_test.
Namespace
Drupal\entity_test\HookCode
public function entityOperationAlter(array &$operations, EntityInterface $entity) : void {
$valid_entity_type_ids = [
'user_role',
'block',
];
if (in_array($entity->getEntityTypeId(), $valid_entity_type_ids)) {
if (\Drupal::service('router.route_provider')->getRouteByName("entity.{$entity->getEntityTypeId()}.test_operation")) {
$operations['test_operation'] = [
'title' => new FormattableMarkup('Test Operation: @label', [
'@label' => $entity->label(),
]),
'url' => Url::fromRoute("entity.{$entity->getEntityTypeId()}.test_operation", [
$entity->getEntityTypeId() => $entity->id(),
]),
'weight' => 50,
];
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.