Block ID rendered incorrectly when added via Layout Builder in IXM Blocks module

Created on 16 October 2024, about 1 month ago

Title:

Block ID rendered incorrectly when added via Layout Builder in IXM Blocks module

Description:

When creating a block through the block interface and adding it manually via the Layout Builder,
the block's ID is rendered incorrectly. For example:

<div id="statistics-"></div>

This happens because, for some reason, the block does not have a revision_id when it's not added inline.
However, if added inline, the issue does not occur.

Steps to reproduce the issue:

  1. Navigate to admin/content/block and add a new IXM block (e.g., statistics, ping-pong, etc.).
  2. Save the block.
  3. Go to a page that uses the Layout Builder and add the newly created block.
  4. You will notice that the block ID is incorrectly rendered as (in my case):
    <div id="statistics-"></div>

Expected behavior:

The block ID should be properly populated based on the available revision_id or fallback to a more consistent identifier.

Proposed solution:

Check if the revision_id exists; if not, use the block’s id instead. Here's a suggestion for how this could be handled in the template:

{% set block_id = 'statistics-' ~ configuration['block_revision_id'] ?? configuration['id']|split(':')[1] %}

...

{% block content %}
  <div id="{{ block_id }}">

This way, even when the block doesn't have a revision_id, it will fallback to a valid identifier.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇧🇷Brazil pinesso

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

Comments & Activities

Production build 0.71.5 2024