diff --git a/metatag.module b/metatag.module index f42ead9..869233e 100644 --- a/metatag.module +++ b/metatag.module @@ -410,12 +410,34 @@ 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) { - $fields['metatag'] = BaseFieldDefinition::create('map') - ->setName('Metatags') + // If the entity type doesn't have a base table then there's no point in + // supporting it. + $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. + $original_class = $entity_type->getOriginalClass(); + $verbotten_classes = [ + 'Drupal\comment\Entity\Comment', + ]; + if (in_array($original_class, $verbotten_classes)) { + return; + } + + // 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); + ->setComputed(TRUE) + ->setTargetEntityTypeId($entity_type->id()); } -