function UserHooks::entityOperation

Implements hook_entity_operation().

File

core/modules/user/src/Hook/UserHooks.php, line 497

Class

UserHooks
Hook implementations for user.

Namespace

Drupal\user\Hook

Code

public function entityOperation(EntityInterface $entity) {
    // Add Manage permissions link if this entity type defines the permissions
    // link template.
    if (!$entity->hasLinkTemplate('entity-permissions-form')) {
        return [];
    }
    $bundle_entity_type = $entity->bundle();
    $route = "entity.{$bundle_entity_type}.entity_permissions_form";
    if (empty(\Drupal::service('router.route_provider')->getRoutesByNames([
        $route,
    ]))) {
        return [];
    }
    $url = Url::fromRoute($route, [
        $bundle_entity_type => $entity->id(),
    ]);
    if (!$url->access()) {
        return [];
    }
    return [
        'manage-permissions' => [
            'title' => t('Manage permissions'),
            'weight' => 50,
            'url' => $url,
        ],
    ];
}

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