function auto_entitylabel_entity_type_alter in Automatic Entity Label 8
Same name and namespace in other branches
- 8.3 auto_entitylabel.module \auto_entitylabel_entity_type_alter()
- 8.2 auto_entitylabel.module \auto_entitylabel_entity_type_alter()
Implements hook_entity_type_alter().
Adds the Auto Label tab to the entity configuration page.
File
- ./
auto_entitylabel.module, line 20 - Allows hiding of entity label fields and automatic label creation.
Code
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) {
// 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");
}
}
}