diff -u b/auto_entitylabel.module b/auto_entitylabel.module --- b/auto_entitylabel.module +++ b/auto_entitylabel.module @@ -17,9 +17,25 @@ * Adds the Auto Label tab to the entity configuration page. */ function auto_entitylabel_entity_type_alter(array &$entity_types) { + $module_handler = \Drupal::moduleHandler(); /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ foreach ($entity_types as $entity_type_id => $entity_type) { - if ($entity_type instanceof ConfigEntityType && $entity_type->hasLinkTemplate('edit-form') && $entity_type->getProvider() != 'page_manager') { + // Support core entity types only. Contrib and custom entity types should + // use a hook or service (@todo https://www.drupal.org/node/2829571). + $core_entity = FALSE; + $module_name = $entity_type->getProvider(); + if ($module_name != 'core') { + // Identify core entity types that are provided by modules. + $module = $module_handler->getModule($module_name); + if (preg_match('/^core/', $module->getPath())){ + $core_entity = TRUE; + } + } + else { + // Some core entity types are not provided by a module. + $core_entity = TRUE; + } + if ($core_entity && $entity_type instanceof ConfigEntityType && $entity_type->hasLinkTemplate('edit-form')) { $entity_type->setLinkTemplate('auto-label', $entity_type->getLinkTemplate('edit-form') . "/auto-label"); } } @@ -108,12 +124,11 @@ $entity_type = $entity->getEntityType(); $entity_type_id = $entity_type->id(); $entity_id = $entity->id(); - if ($entity_type instanceof ConfigEntityType && - $entity->hasLinkTemplate('auto-label') && + if ($entity->hasLinkTemplate('auto-label') && \Drupal::currentUser()->hasPermission('administer ' . $entity_type_id . ' labels')) { $operations['auto-label'] = array( - 'title' => t('Automatic entity label'), + 'title' => t('Manage automatic entity labels'), 'weight' => 100, 'url' => Url::fromRoute("entity.{$entity_type_id}.auto_label", array($entity_type_id => $entity_id)), ); diff -u b/src/AutoEntityLabelPermissionController.php b/src/AutoEntityLabelPermissionController.php --- b/src/AutoEntityLabelPermissionController.php +++ b/src/AutoEntityLabelPermissionController.php @@ -55,14 +55,14 @@ foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { // Create a permission for each entity type to manage the entity // labels. - if ($entity_type->hasLinkTemplate('auto-label') && $entity_type->hasKey('label') && $entity_type instanceof ConfigEntityType) { + if ($entity_type->hasLinkTemplate('auto-label') && $entity_type->hasKey('label')) { $permissions['administer ' . $entity_type_id . ' labels'] = [ 'title' => $this->t('%entity_label: Administer automatic entity labels', ['%entity_label' => $entity_type->getLabel()]), 'restrict access' => TRUE, ]; } } - // Permission to use PHP in entity label patterns + // Create permission to use PHP in entity label patterns. $permissions['use PHP for auto entity labels'] = [ 'title' => $this->t('Use PHP for automatic entity label patterns'), 'restrict access' => TRUE,