Seeing error with metatags.

Drupal\Core\Entity\EntityStorageException: Field Metatags is unknown. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 770 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Entity\ContentEntityBase->get('Metatags') (Line: 660)
_content_sync_db_to_entity('node', 'landing_page', '5554') (Line: 215)
content_sync_entity_update(Object) (Line: 229)
content_sync_entity_insert(Object)
call_user_func_array('content_sync_entity_insert', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_insert', Array) (Line: 169)
Drupal\Core\Entity\EntityStorageBase->invokeHook('insert', Object) (Line: 441)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('insert', Object) (Line: 470)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, ) (Line: 326)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, ) (Line: 395)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 761)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 364)

Comments

john.money created an issue. See original summary.

john.money’s picture

Spent some more time testing, disabling the metatags module (after first removing all metatag field instances) resolves this issue. Still need path forward for both modules to co-exist.

blanca.esqueda’s picture

Category: Bug report » Feature request

Hi @john.money

Version 8.x-1.x supports only the Drupal core fields (as mentioned on the project page description), that's the reason why you were getting that error.

---

But we have a new version 8.x-2.x, that it is able to handle custom fields (as paragraphs) so probably it can handle metatags.
Please feel free to pull version 8.x-2.x and do some testing and if possible let us know the results.

Be aware that the yaml files are different from one version to the other as some changes were needed to implement new functionality (that means the same version has to run on the source and target sites).

Note that version 8.x-2.x is a beta, so be careful to create backups before importing.

blanca.esqueda’s picture

I did some testing with Drupal 8.4, content_sync 8.x-2.x , and metatag 8.x-1.3

Unfortunately there is a conflict.
errors:
Drupal\Core\Entity\EntityStorageException: Object support when dumping a YAML file has been disabled. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()

Drupal\Component\Serialization\Exception\InvalidDataTypeException: Object support when dumping a YAML file has been disabled. in Drupal\Component\Serialization\YamlSymfony::encode()

socialnicheguru’s picture

Just ran into the errors outlined in #4

janlaureys’s picture

I was testing this module as well because it seems like a perfect fit for our use case, but ran into this issue as well.

Apparently because it's using the YamlSymfony class to encode data to yaml and the dump function gets a SymfonyYaml::DUMP_EXCEPTION_ON_INVALID_TYPE parameter rather than a SymfonyYaml::DUMP_OBJECT and the metatags field looks like this:

[field_metatags] => Array ( [0] => Drupal\Core\StringTranslation\TranslatableMarkup Object ( [string:protected] => Metatags are normalized in the metatag field. [translatedMarkup:protected] => [options:protected] => Array ( ) [stringTranslation:protected] => [arguments:protected] => Array ( ) ) )

amenzou’s picture

It's not an issue with content_sync. Metatag didn't implement their FieldItemNormalizer correctly. The normalize() function should return an instance of the $supportedInterfaceOrClass which is Drupal\metatag\Plugin\Field\FieldType\MetatagFieldItem, but instead a Translation object is returned;
Implementation fail
---
Instead of just saying normalization is not supported, they should've implemented the method made for that exact purpose;

/**
   * {@inheritDoc}
   */
  public function supportsNormalization($data, $format = NULL){
    return false;
  }
webfaqtory’s picture

I can confirm that making the following changes to metatag/src/Normalizer/FieldItemNormalizer.php solves the problems with #4

class FieldItemNormalizer extends NormalizerBase {

  /**
   * {@inheritdoc}
   */
  protected $supportedInterfaceOrClass = 'Drupal\metatag\Plugin\Field\FieldType\MetatagFieldItem';

  /**
   * {inheritDoc}
   */
  public function normalize($object, $format = NULL, array $context = []) {
    //return t('Metatags are normalized in the metatag field.');
    return $supportedInterfaceOrClass;
  }
  
  /**
   * {@inheritDoc}
   */
  public function supportsNormalization($data, $format = NULL){
    return false;
  }

}
blanca.esqueda’s picture

Status: Active » Closed (works as designed)
Related issues: +#2903457: Normalizer problem when Metatag is enabled

amenzou and webfaqtory,

Added your notes on the following Metatag issue:
https://www.drupal.org/project/metatag/issues/2903457#comment-12660595

Thank you so much!