function entity_test_entity_operation_alter

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_operation_alter()
  2. 8.9.x core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_operation_alter()
  3. 10 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 491

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,
            ];
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.