You are here

function auto_entitylabel_entity_operation in Automatic Entity Label 8

Same name and namespace in other branches
  1. 8.3 auto_entitylabel.module \auto_entitylabel_entity_operation()
  2. 8.2 auto_entitylabel.module \auto_entitylabel_entity_operation()

Implements hook_entity_operation().

File

./auto_entitylabel.module, line 125
Allows hiding of entity label fields and automatic label creation.

Code

function auto_entitylabel_entity_operation(EntityInterface $entity) {
  $operations = [];
  $entity_type = $entity
    ->getEntityType();
  $entity_type_id = $entity_type
    ->id();
  $entity_id = $entity
    ->id();
  if ($entity
    ->hasLinkTemplate('auto-label') && \Drupal::currentUser()
    ->hasPermission('administer ' . $entity_type_id . ' labels')) {
    $operations['auto-label'] = [
      'title' => t('Manage automatic entity labels'),
      'weight' => 100,
      'url' => Url::fromRoute("entity.{$entity_type_id}.auto_label", [
        $entity_type_id => $entity_id,
      ]),
    ];
  }
  return $operations;
}