diff --git a/metatag.module b/metatag.module index 869233e..b85b254 100644 --- a/metatag.module +++ b/metatag.module @@ -409,35 +409,27 @@ function metatag_get_default_tags($entity = NULL) { /** * Implements hook_entity_base_field_info_alter(). */ -function metatag_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) { - // If the entity type doesn't have a base table then there's no point in - // supporting it. +function metatag_entity_base_field_info(EntityTypeInterface $entity_type) { + $fields = []; $base_table = $entity_type->getBaseTable(); - if (empty($base_table)) { - return; - } - - // The entity type must also have a canonical route. - if (!$entity_type->hasLinkTemplate('canonical')) { - return; - } - - // Certain classes are just not supported, end of story. + $canonical_template_exists = $entity_type->hasLinkTemplate('canonical'); + // Certain classes are just not supported. $original_class = $entity_type->getOriginalClass(); - $verbotten_classes = [ + $classes_to_skip = [ 'Drupal\comment\Entity\Comment', ]; - if (in_array($original_class, $verbotten_classes)) { - return; + + // If the entity type doesn't have a base table, has no link template then there's no point in + // supporting it. + if (!empty($base_table) && $canonical_template_exists && !in_array($original_class, $classes_to_skip)) { + $fields['metatag'] = BaseFieldDefinition::create('map') + ->setLabel(t('Metatags')) + ->setDescription(t('The metatags for the entity.')) + ->setClass('\Drupal\metatag\Plugin\Field\MetatagEntityFieldItemList') + ->setQueryable(FALSE) + ->setComputed(TRUE) + ->setTargetEntityTypeId($entity_type->id()); } - // If the entity type hasn't been skipped above, then create the Metatag - // field thing. - $fields['metatag'] = BaseFieldDefinition::create('map')->setName('Metatags') - ->setLabel(t('Metatags')) - ->setDescription(t('The metatags for the entity.')) - ->setClass('\Drupal\metatag\Plugin\Field\MetatagEntityFieldItemList') - ->setQueryable(FALSE) - ->setComputed(TRUE) - ->setTargetEntityTypeId($entity_type->id()); + return $fields; }