Block attributes are not passed to the contained block

Created on 4 November 2024, about 1 month ago

Problem/Motivation

Using modules like fences_block (or solving it code-wise) you'd be willing to set attributes on blocks, e.g. wrapper, label, content, ...

But when using block_ajax, these are not applied to the contained block, loaded via AJAX.

Steps to reproduce

Enable block_ajax for a block with fences_block enabled and fences settings or attributes set. The settings are not applied anymore.

Proposed resolution

Pass the attributes to the AJAX'ified block like it was a native block
Eventually add a setting for this, if it's really needed

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica

    Okay, fences returns here for ajax_block blocks:

        if (!$block instanceof ThirdPartySettingsInterface) {
          return;
        }
    

    in FencesBlock.php, Line 30

    The question is, why the block doesn't have the ThirdPartySettingsInterface here.

  • 🇩🇪Germany Anybody Porta Westfalica

    Okay in our case, for example $element['#id'] was == "commerce_cart". But the issue seems to be, that

    Block::load($element['#id']);
    

    in FencesBlock.php
    tries to load a conflig block, which does not exist, as the configuration resists in the ajax_block!
    See https://drupal.stackexchange.com/a/171733 for details.

    So the block that holds the third party settings is not commerce_cart, but the placed ajax_block instance!

    So this needs a different strategy to pass the attributes from the pseudo ajax_block to the ajax-loaded content block. It can't be fixed directly.

    There's already some logic in block_ajax_block_view_alter() but as this case shows, it doesn't fully mimic the contained block and doesn't pass all the third party settings and alterations yet.

    I'm not yet sure how to solve this, but as we can see it's specific to third party alterations, I'm reducing the priority to normal.

Production build 0.71.5 2024