Cloned entities don't retain their Inline Block usage

Created on 19 June 2019, over 5 years ago
Updated 30 July 2024, 5 months ago

When cloning an entity either via code or via a module such as Entity Clone the inline block usage is not carried over, meaning if you delete the original entity, the inline blocks will be removed and break the clone.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Layout builder 

Last updated 2 days ago

Created by

🇨🇦Canada b_sharpe

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States amitchell-p2

    This is a clean re-roll of #17 for 9.5.5 in prep for next patch.

  • 🇺🇸United States amitchell-p2

    This builds on #35 and includes a fix that addresses the issue noted in #32 and earlier that comes up when using entity_clone, mentioned in #48 on this entity_clone issue: https://www.drupal.org/project/entity_clone/issues/3050027#comment-14915222 🐛 Inline Blocks on Layout Builder Fail to Clone Correctly Needs work

    When cloning, getPluginBlockId($plugin) uses the revision ID of the new revision on the new block to retrieve the block id from a db query. Due to the order of operations here, that id may not be returned from the db query. This causes addUsages() to fail because it is passed a null value for the id.

    In this case, the new block is referenced by the plugin. The plugin's getEntity() is a protected method, so we use reflection to call it and get the entity id from there. Then we pass the id to the addUsages() function like would have happened otherwise:

          $id = $this->getPluginBlockId($plugin);
          if(!$id){
            // The standard getPluginBlockId() didn't return an id, let's use
            // reflection to get it off of the $plugin.
            // We have to use reflection for this as it's a protected method.
            $reflectionMethod = new \ReflectionMethod($plugin, 'getEntity');
            $reflectionMethod->setAccessible(TRUE);
            $new_entity = $reflectionMethod->invoke($plugin);
            $id = $new_entity->id();
          }
          $this->usage->addUsage($id, $entity);
    
  • 🇪🇸Spain alvarodemendoza

    Confirming that patch in #36 works with 10.2.6 core.
    Errors we found before the patch with all clone modules like quick node clone:
    - Deleting a block from the original entity throws a missing block error on the cloned page.
    - Adding new media to cloned pages throws a access dependency error and therefore when you clock add media nothing happens.

  • Status changed to Needs review 7 months ago
  • Status changed to Needs work 7 months ago
  • The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • 🇮🇳India soutams

    I'm still facing the issue in Drupal 10.2.6 after applying the patch #36

    inline block content is showing as the last updated/translated block content.I'm using layout builder st. I faced the same issue in Drupal 9. After applying the patch #16 it got resolved. Recently I upgraded to drupal 10. Now again I'm getting the issue. I've already tried #36 patch.

    Thanks in advance.

  • 🇩🇪Germany sandro_pagliara

    We get the error in 10.3.0 as well.
    Layout builder st is also used.

  • remoschneider Stuttgart, Germany

    I updated patch #36 for Drupal 10.3.0, correcting only the positioning of changes within InlineBlockEntityOperations.php, which previously caused the patch application to fail.

  • 🇧🇪Belgium RandalV

    Hi @remoschneider,

    Please, refrain from posting a patch that isn't functionally brought up to date.
    The patch you posted applies, but is buggy due to the lack of the 'getPluginBlockId'-method in the InlineBlockEntityOperations class.

    I'll post a patch that is functionally in line with the old one, if someone wants to turn it into an MR.

  • Was getting this error upon editing and saving a LB page on 10.3.1:

    Error: Call to undefined method Drupal\layout_builder_st\InlineBlockEntityOperations::getPluginBlockId() in Drupal\layout_builder\InlineBlockEntityOperations->saveInlineBlockComponent() (line 259 of /var/www/html/docroot/core/modules/layout_builder/src/InlineBlockEntityOperations.php)

    I uninstalled layout_builder_st, but was still getting the error, although this time pointing to `layout_builder`:

    Error: Call to undefined method Drupal\layout_builder\InlineBlockEntityOperations::getPluginBlockId() in Drupal\layout_builder\InlineBlockEntityOperations->saveInlineBlockComponent() (line 259 of /var/www/html/docroot/core/modules/layout_builder/src/InlineBlockEntityOperations.php).
    

    I then updated from #43 version of this patch to the version from #44 and issue was resolved.

Production build 0.71.5 2024