Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When placing a field in the hidden region of a layout, a notice that `ds_hidden` is undefined is thrown.
Comment | File | Size | Author |
---|---|---|---|
#15 | 2912149-15.patch | 0 bytes | swentel |
#13 | 2912149-13.patch | 83.87 KB | swentel |
#9 | undefined_index_field_in_ds_preprocess_ds_layout-2912149-9.patch | 1011 bytes | ssantaeugenia |
#4 | fix_ds_hidden-2912149-04.patch | 548 bytes | partdigital |
Comments
Comment #2
arti5m CreditAttribution: arti5m commentedComment #3
partdigital CreditAttribution: partdigital commentedThis is an old issue but I was experiencing the exact same issue. I found that it was being caused by a variable name collision when I created a custom template.
For example I had this template, note the "content" region.
When this goes through preprocess function it gets passed like this.
When the ds module did its preprocessing it replaced the Drupal core $variables['content']; variable with $variables['content']['content']. This caused all the fields and other properties to immediately get destroyed causing the undefined index error.
The quick fix
Don't name your region "content" in your template.
The fix:
I don't think we should be replacing all the variables in $variables['content'] but I also understand that we need to pass up the regions to the top level. I've revised the code a bit so that it doesn't overwrite $variables['content'], however now that region is not being passed. I think that is acceptable given that developers will still have all the variables they need and this should only happen in relative edge cases.
Comment #4
partdigital CreditAttribution: partdigital commentedI ran into some issues with the previous patch. Content would render twice. I've updated the patch, now the "content" variable gets replaced which was the original behavior but without the undefined index notice. I'd like to hear some thoughts, is this the correct direction to go in?
Comment #5
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedVery interesting! I guess that's why we use 'ds_content' in the one col layout we ship.
But 'content' should work because it's easy to hit this bug; let's see what the bot think. Will definitely work on this and add a test for it!
Comment #6
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedOk, looks like the approach is fine. Definitely needs tests though.
I can work on that next week, unless someone beats me to it.
Comment #7
partdigital CreditAttribution: partdigital commented@Swentel, is there a particular approach that you prefer? #3 vs #4? If #3 is the preferred method (which is the one I'm learning towards, but admittedly I'm not an expert on Display Suite), I can look at my use case again and see why it was duplicating the content.
Comment #8
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commented@partdigital Hmm. #3 makes sense because of the isset() check. It's been a while since I looked what's inside $variables['content']. but I think in both cases we probably lose data which might be important further in the process.
I also just looked at how layout_discovery handles this, and the templates use {{content.content}} which makes more sense. This is definitely something which I want to change in 8.x-4.x so we don't copy over all that data anymore.
So maybe we should document that for 8.x-3.x you shouldn't use 'content' as a region and use this issue then to fix it for 8.x-4.x?
Note: if you want to keep on looking, I would appreciate that. I will credit you anyway when I commit the 8.x-4.x part, because without this ping/insight I would probably have never started working on that.
Comment #9
ssantaeugenia CreditAttribution: ssantaeugenia commentedThanks,
I have the same problem for the fields of a content type.
A validation isset() seems to work.
This is the patch that has worked for me.
Comment #10
partdigital CreditAttribution: partdigital commented@swentel thanks, I will do some more investigating into the #3 approach then and see why it was duplicating content. I should be able to look at this again later this week or early next week.
Comment #11
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedMoving to right branch.
Comment #12
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedComment #13
swentel CreditAttribution: swentel at eps & kaas commentedComplete rewrite of some stuff. The templates now follow the layout pattern: content.{region}
Comment #15
swentel CreditAttribution: swentel at eps & kaas commentedFixing dependencies
Comment #21
swentel CreditAttribution: swentel at eps & kaas commentedComment #22
swentel CreditAttribution: swentel at eps & kaas commentedComment #23
swentel CreditAttribution: swentel at eps & kaas commentedLet's see if we can get this into 8.x-3.x with BC
Comment #24
swentel CreditAttribution: swentel at eps & kaas commentedComment #25
swentel CreditAttribution: swentel at eps & kaas commented