You are here

function scheduled_transitions_entity_operation in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x scheduled_transitions.module \scheduled_transitions_entity_operation()

Implements hook_entity_operation().

File

./scheduled_transitions.module, line 32

Code

function scheduled_transitions_entity_operation(EntityInterface $entity) : array {
  $operations = [];
  if ($entity
    ->getEntityType()
    ->hasLinkTemplate(ScheduledTransitionsRouteProvider::LINK_TEMPLATE_ADD)) {
    $routeName = ScheduledTransitionsRouteProvider::getScheduledTransitionRouteName($entity
      ->getEntityType());
    $url = Url::fromRoute($routeName, [
      $entity
        ->getEntityTypeId() => $entity
        ->id(),
    ]);
    $user = \Drupal::currentUser();
    if (TRUE === $url
      ->access($user)) {
      $operations['scheduled_transitions'] = [
        'title' => \t('Scheduled transitions'),
        'url' => $url,
        'weight' => 50,
      ];
    }
  }
  return $operations;
}