Custom blocks created in inline forms should not be reusable

Created on 25 September 2018, over 6 years ago
Updated 8 August 2024, 5 months ago

Problem/Motivation

Common problem with managing structured content (based on core blocks and/or paragraphs) is separating reusable and non-reusable content "units".

Core custom blocks are stable, reusable units.

Paragraphs excel as non-reusable units.

Real problem arises when you need to combine both reusable and non-reusable units in one field.

`paragraphs_library` module which is a submodule of paragraphs, exposes its own entity type, that cannot be referenced in the same way as paragraphs.

Custom blocks in core have reusable flag since 8.6.0 β†’ , so it should be possible to use it. The logic discussed during Darmstadt layout builder BoF is as follows:

- entities created in custom block library are implicitly reusable
- entities created when editing container entity with layout builder are implicitly non-reusable

I think the same logic applies to inline entity form - when custom blocks are added to container entity with IEF ('Add new'), they should be marked non-reusable.@valthebald, thanks a lot for crafting the #2 patch. Even if i rolled it completely different now, i immediately could see where to grip.

Patch flying in that inlines the code and has some comment (tbh, more than code ;-).

That would give content editors experience that is on par with paragraphs, using only core custom blocks and inline entity form.

Proposed resolution

- Add new CustomBlockInlineForm class
- in `inline_entity_form_entity_type_build()`, set handler class for `block_content` entity type (if content block module is enabled)
- Set CustomBlockInlineForm::entityFormSubmit(), set reusability flag to false

Caveat here: since the flag exists only in Drupal 8.6+, we probably need to check if function exists (or require core version in module dependencies - which probably is overkill?)

Remaining tasks

- Write the patch
- Update the "Proposed resolution" section. See Comment #38.

2976334

✨ Feature request
Status

Needs work

Version

3.0

Component

Code

Created by

πŸ‡§πŸ‡¬Bulgaria valthebald Sofia

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • πŸ‡―πŸ‡΄Jordan Odai Atieh Amman

    Just created a patch for the MR

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    1 pass, 16 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 11 months ago
    PHPLint Failed
  • πŸ‡ΊπŸ‡¦Ukraine alt.dev

    I made a fix when nested blocks added via the inline_entity_form module didn't have the edit button visible when you edit the block. Also, this fix fixes the issue when you can't see nested blocks while the node is not saved.

    This patch can be applied to Drupal 10.2.x.

  • πŸ‡ΊπŸ‡ΈUnited States adam-delaney

    > The LB module declares its event subscriber in a ServiceProvider class instead of in its .services.yml file. This is because it is conditional: it should only be defined if the block_content module is enabled. This patch just declares the subscriber in the .service.yml file, but perhaps it would be better to use a ServiceProvider class. I have not tested whether this patch causes problems when LB is not enabled.

    I've tested this with a new site install that does not enable block_content and this will throw the following error: `Error: Class "Drupal\block_content\BlockContentEvents" not found in Drupal\inline_entity_form\EventSubscriber\SetInlineBlockDependencyNested::getSubscribedEvents()`

  • πŸ‡ΊπŸ‡ΈUnited States adam-delaney

    I've created a new patch from patch 44 that removes the services.yml in favor of a ServiceProvider that dynamically defines inline_entity_form.get_block_dependency_subscriber if block_content is enabled. I have also checked that block_content is enabled in hook_entity_presave() as that was erroring as well.

  • πŸ‡ΊπŸ‡ΈUnited States froboy Chicago, IL

    This won't be useful to too many folks, but here's #46 that applies to the now abandoned 2.x branch.

  • πŸ‡ΊπŸ‡ΈUnited States froboy Chicago, IL

    If you have a bunch of existing blocks it may be useful to run an update hook to set the them all to be non-reusable. Here's what I did so it might help others:

    /**
     * Set blocks that should not be reusable to non-reusable.
     */
    function my_module_update_9001(&$sandbox) {
      $count = 0;
      $block_storage = \Drupal::service('entity_type.manager')->getStorage('block_content');
      $ids = \Drupal::entityQuery('block_content')
        ->condition(/* Some condition if you're able to identify only certain block types to fix. */)
        ->condition('reusable', '1', '=')
        ->accessCheck(FALSE)
        ->execute();
      foreach ($ids as $id) {
        // Loop through blocks and set them to non-reusable.
        /** @var \Drupal\block_content\Entity\BlockContent $updated */
        $block = $block_storage->load($id);
        $updated = $block->setNonReusable()->save();
        if ($updated == 2) {
          $count++;
        }
      }
      \Drupal::messenger()
        ->addMessage(t('Updated @count blocks.', [
          '@count' => $count,
        ]));
    }
    
  • Status changed to Needs work 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States froboy Chicago, IL

    Reopening this for consideration on the 3.x branch. I think it could be a useful addition. Will try to come back to it with updates if it's wanted.

  • πŸ‡ΊπŸ‡ΈUnited States adam-delaney

    Patch #46 breaks due to upstream change in Drupal Core 10.3 InlineBlockEntityOperations, see commit: https://git.drupalcode.org/project/drupal/-/commit/71a1ab746b9731cb30213.... This change removes the parent getPluginBlockId method and causes a WSOD. It looks like that method was getting the plugin id from configuration so the patch could likely be updated to code around this. I don't see this patch as long term viable unless core allows for these classes and services to be open to contrib projects so we are planning on getting out of this patch.

  • πŸ‡ΊπŸ‡ΈUnited States froboy Chicago, IL

    @adam-delaney thanks for the warning.

  • First commit to issue fork.
  • πŸ‡¨πŸ‡¦Canada arakwar

    I tested one of our project without the patch and it created more issues for us.

    I added the missing function back in the module. I also applied patch #46 on MR !38, just to make it easier to continue to work on this issue until it's resolved.

Production build 0.71.5 2024