function user_entity_operation in Drupal 10
Implements hook_entity_operation().
File
- core/
modules/ user/ user.module, line 1306 - Enables the user registration and login system.
Code
function user_entity_operation(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,
],
];
}