You are here

function entity_test_entity_operation_alter in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_operation_alter()

Implements hook_entity_operation_alter().

File

core/modules/system/tests/modules/entity_test/entity_test.module, line 569
Test module for the entity API providing several entity types for testing.

Code

function entity_test_entity_operation_alter(array &$operations, EntityInterface $entity) {
  $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,
      ];
    }
  }
}