When testing https://www.drupal.org/project/facets/issues/3052574 I discovered that block attributes and contextual links are reset when using twig tweak.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | twig_tweak-fix-block-attributes-3270062-18.patch | 785 bytes | ludo.r |
| #2 | 3068078-fix-block-attributes.patch | 796 bytes | aspilicious |
Comments
Comment #2
aspilicious commentedComment #3
chi commentedThis needs steps to reproduce.
Comment #4
chi commentedComment #5
aspilicious commentedSee linked issue
1) Install twig tweak
2) Create a search view (ajax)
3) Create a facet linked to the view
4) Create a custom block with a twig template
5) Add following template
{{ drupal_block('facet_block:facet_id') }}
{{ drupal_view('view_name', 'block') }}
Comment #6
chi commentedContextual links for embed views are not supported. See the issue referenced in #4.
Comment #7
aspilicious commented? I don't understand your comment.
I can remove the contextual link part from the patch if you want.
Comment #8
chi commentedI think the patch needs a test that proves the bug.
Comment #9
aspilicious commentedFair, but with 3 little kids at home I have little time at the moment to write the test.
So if someone want to help this issue forward, I think looking at the current test the easiest approach is
1) Create a hook_block_view_alter in the test module
2) Add a random class in #attributes
3) Add an extra xpath check in the functional test file to verify it's available
Comment #10
mikechr commentedI was having the same issue and tracked down the problem to
twig_tweak/src/TwigExtension::drupalBlock
As seen below the attributes and contextual_links of the block are removed. The patch #2 provided fixed the problem.
Comment #11
chi commentedI've just found a way to reproduce it without contributed modules. The core Language block plugin does set attributes. However simple coping them to the build array may produces duplicated attributes in an inner element. I think the proper way to handle this is moving attributes and contextual links from
$build['content']to$build. That's what Drupal core does.https://git.drupalcode.org/project/drupal/-/blob/9.0.0-beta2/core/module...
Comment #13
chi commentedFixed in 3.x. I don't think that can be backported to 2.x as moving attributes may break CSS selectors on existing sites which is a BC break.
Thank you.
Comment #15
eliaspapa commentedI believe this needs to be re-opened. The patch will only work up to version 2.6 and not up to 2.9 which is the latest version. I think some minor modifications need to be done to the patch, maybe the file changed a bit in those versions. If this has been indeed fixed in version 3.x then all we need is this minor change to this patch.
Comment #16
chi commented@EliasPapa that can cause BC break. See note #13.
Comment #17
sany_86@bk.ru commentedAbout contextual links, I was able to do it in this way for Block Content in node template:
Maybe it will be helpful.
Comment #18
ludo.rPatch re-rolled against
8.x-2.x-dev