diff -u b/auto_entitylabel.module b/auto_entitylabel.module --- b/auto_entitylabel.module +++ b/auto_entitylabel.module @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Config\Entity\ConfigEntityType; use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Url; /** * Implements hook_entity_type_alter(). @@ -100,0 +102,22 @@ + +/** + * Implements hook_entity_operation(). + */ +function auto_entitylabel_entity_operation(EntityInterface $entity) { + $operations = array(); + $entity_type = $entity->getEntityType(); + $entity_type_id = $entity_type->id(); + $entity_id = $entity->id(); + if ($entity_type instanceof ConfigEntityType && + $entity->hasLinkTemplate('auto-label') && + \Drupal::currentUser()->hasPermission('administer ' . $entity_type_id . ' labels')) { + + $operations['auto-label'] = array( + 'title' => t('Automatic entity label'), + 'weight' => 100, + 'url' => Url::fromRoute("entity.{$entity_type_id}.auto_label", array($entity_type_id => $entity_id)), + ); + } + + return $operations; +} \ No newline at end of file diff -u b/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php --- b/src/Routing/RouteSubscriber.php +++ b/src/Routing/RouteSubscriber.php @@ -63,7 +63,7 @@ $route ->addDefaults([ '_form' => '\Drupal\auto_entitylabel\Form\AutoEntityLabelForm', - '_title' => 'Auto Label', + '_title' => 'Automatic entity label', ]) ->addRequirements([ '_permission' => 'administer ' . $entity_type_id . ' labels',