Problem/Motivation

Revert of #3206625: ID attribute is missing from blocks rendered by BlockFieldFormatter.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 revert-block-id-3223741-2.patch1.66 KBberdir
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new1.66 KB

Just a direct revert patch for now, I'm open to patches that add a HTML attribute as discussed in that other issue or through a #block_field_id or whatever.

anybody’s picture

I agree this makes sense, at least it should not simply use ->getMachineNameSuggestion() but maybe add a block_field prefix or suffix or something like that. Of course that's also no *real* solution, but better than predicting it's something it isn't and risking duplications.

How to proceed here?

Background: We wanted to determine the region the *real* block (not the block field) is in (by checking #id). But without this patch they all have the same #id so this isn't possible. Maybe @Berdir had similar issues in his projects?
So +1 on reverting that change (and looking at the suggestion above to have *an* #id (but not the same).

PS: Maybe it would be good in general to indicate that this is a block rendered by block_field? (which would also happen by the prefix / suffix, so I like the idea so far...)
PPS: I implemented that as POC for discussion in the MR.

anybody’s picture

@Berdir: Any feedback eventually (if you should have the time)?

berdir’s picture

Status: Needs review » Needs work

A prefix isn't going to help. There's still going to be code that assumes #id is a block config entity and will try to load that.

My suggestion in #2 is a separate property like #block_field_id, then you can find it if you're looking for it, although I personally don't think that is very useful because the machine name *suggestion* is a transliterated and adjusted version of the admin label and nothing that you should rely on in code.

region is a block config entity concept, it does not exist for block_field blocks. but you could say that all block_field blocks are in a in-content pseudo region, then some kind of flag could be useful.

I'm unsure about committing this because it's been 3 years now and even though the project isn't stable, it's still a change.

anybody’s picture

Thanks @Berdir I added #25 - don't have the time now to look into it deeper, especially what to use for the id attribute, but this should be a first step.

Regarding

although I personally don't think that is very useful because the machine name *suggestion* is a transliterated and adjusted version of the admin label and nothing that you should rely on in code.

That's right, but in that case we needed a way to determine the right one and that was the only specific option here. Good enough for that project in other words. No general solution of course.

How should we proceed?