Entity references set with Inline Entity Form disappear when clicking to Seo preview button and saving the node

Created on 18 February 2025, 3 months ago

Problem/Motivation

1. create a node type with
- a Yoast SEO field
- and a multi value reference field to nodes called "Similar content"
2. set form widget for "Similar content" field to "Inline Entity Form - Simple"
3. open a node add form
4. do not click the "Seo preview" yet
5. for the sake of testing, add 3 new elements to "Similar content" with titles: content1, content2, content3
6. in "Yoast SEO" fill in "Focus keyword" and click the "Seo preview" button 1 or 2 times
7. click Save on the bottom
8. notice that the "content3" reference we set disappeared. It was never even saved if you check it on /admin/content. Therefore I have to raise the priority of this issue to critical.
9. now, open the edit form of the node that was created
10. in "Yoast SEO" click the "Seo preview" button 1 or 2 times
11. click Save on the bottom
12. notice that the "content2" reference disappeared. "Similar content" now has "content1" only even though we set 3 node references there in step 5.

This problem does apply for all other entities where Yoast SEO is present, too (Commerce Products, Taxonomy terms etc.)

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia kaszarobert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kaszarobert
  • πŸ‡΅πŸ‡±Poland zambrey

    I can confirm that this module breaks the entity reference fields (in my case with Media Library widget) where the weight of the items is not saved.

    The problem is most likely related with changing the handler class for entity forms in yoast_seo.module:

    function yoast_seo_entity_type_build(array &$entity_types) {
      /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
      foreach ($entity_types as &$entity_type) {
        if (!$entity_type->hasHandlerClass('yoast_seo_preview_form')) {
          $entity_type->setHandlerClass('yoast_seo_preview_form', AnalysisFormHandler::class);
        }
      }
    }

    Commenting out the line with setHanderClass() call fixes for me the issue with item ordering.

  • πŸ‡«πŸ‡·France guilhom Toulouse

    I struggled with a bug with the Media Library widget where the weight wasn't being saved correctly until I discovered that removing the field from this Yoast module made everything go back to normal.

    Did you find a solution zambrey to solve this issue because I assume that creating a patch to comment this line will break the Yoast SEO plugin behavior ?

  • πŸ‡΅πŸ‡ΉPortugal neliofga

    I can also confirm that the Media Library widget no longer saves the item weights when the Real-time SEO field is included.

    There's another open issue regarding the same behavior:
    https://www.drupal.org/project/yoast_seo/issues/3354563 πŸ› Medialibrary sorting not working, when module is in use Active

    It appears to happen while building the entity in the AnalysisFormHandler: $preview_entity = $form_object->buildEntity($form, $form_state);

      public function cacheProcessedEntityForPreview(array $form, FormStateInterface $form_state) {
        // Prevent firing accidental submissions from entity builder callbacks.
        $form_state->setTemporaryValue('entity_validated', FALSE);
        $form_object = $form_state->getFormObject();
        assert($form_object instanceof EntityFormInterface, "Calling " . __FUNCTION__ . " for a form that's not an entity form is invalid.");
        $preview_entity = $form_object->buildEntity($form, $form_state);
        $form_state->setTemporaryValue('preview_entity', $preview_entity);
      }
    
Production build 0.71.5 2024