When adding a multi-value node file field to a panel node, the offset (i.e. "Skip the first [x] items") no longer works as expected. Apparently this has been happening since version 7.x-1.6 but I didn't run into it until upgrading to 7.x-1.7.
To replicate:
- Add a multi-value node file field (e.g., an image field that accepts multiple images) to Content types > Panel > Manage fields.
- Create a panel node.
- Add multiple images to the file field.
- On the Panel Content page, add a Node > [field you created] pane to a panel region. When you get to the Formatter Styles overlay, set the "Skip the first [x] items" to a value other than zero and set the "Then display at most [x] items" to a value higher than 1.
When you view the panel, you'll see that the number of images being displayed does not match the delta_offset and limit values you specified. Usually, only one or none is displayed, depending on the number of images in the field and the offset/limit you specified.
I was able to solve this by modifying the entity_field.inc file located here:
ctools/plugins/content_types/entity_context/entity_field.inc
The culprit was a parameter on the array_splice function on line 144. This line takes all values for a multi-value field and creates a subset based on the offset and limit you specified. By default, array_splice resets array keys unless, as in this case, the final parameter is set to TRUE. By removing the TRUE parameter and allowing array_slice to reset the keys, the offset and limit will then work as expected.
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | ctools-offset-rendering-2456327-40.patch | 975 bytes | dasha_v |
| #30 | ctools-offset-rendering-2456327-30.patch | 734 bytes | dasha_v |
Comments
Comment #1
davidrf commentedComment #3
davidrf commentedThis was my first patch contribution ever, so any guidance as to why the patch failed testing would be greatly appreciated.
Comment #4
davidrf commentedResubmitting the patch (modified).
Comment #5
davidrf commentedComment #7
kcolwell commentedThanks... This solved a problem that I was experiencing on a test site. Sorry I can't be of any help on why the patch is failing the tests.
Comment #8
kepford commentedThanks for the patch @davidrf. It looks like your patch failed because you did it relative to your doc root vs. the module directory. I tested and rerolled it. I'm going to put this patch through more testing but it appears to have solved the issue so thanks and welcome to contributing code!
Comment #9
damienmckennaThanks for the patch, davidrf!
FYI don't set the "assigned" to yourself unless you're specifically working on it.
Comment #10
christoph commentedI think I may have tracked down the source of this issue to Drupal Core / Fields Module. The bug I posted for that is https://www.drupal.org/node/2456573.
Essentially the fields modules changes the keys of the array whereas when the field contents are cloned in CTools these keys are kept. I feel the solution is more in fields, but it is possible that by changing line 144 of ctools/plugins/content_types/entity_context/entity_field.inc to not keep i.e. to FALSE field keys that works as well:-
However this feels an incorrect solution.
There is a work around for us at the moment at the theming layer. If you take the field.tpl.php for your specific field (e.g. field--field-name.tpl.php) where you are having this issue, you can add this code at the beginning:-
This corrects the key issue we were having. I hope this helps in the mean time as the root cause if solved.
Comment #11
davidrf commentedcristoph - We initially addressed this at the field.tpl.php level, but that's more logic than we're comfortable with in a template file. That's why I went hunting for the culprit in the module.
Thanks everyone for the feedback!
Comment #12
jkopel commentedI just ran into this when updating a site from 1.5 - 1.7 and #8 worked well for me.
Nice job @davidrf, thanks!
Comment #13
kutulus commentedHi,
I ran into the same offset problem with Display Suite - Dynamic Code Field
When adding a multi-value node file field to a View-Mode, the offset (i.e. "Skip the first [x] items") no longer works as expected. This has been happening with version 7.x-1.6 and 7.x-1.7.
Patch #8 works fine.
Thanks for your work.
Comment #14
Sneakyvv commentedI've spent hours debugging to find the problem, and came to the same solution, only to find there's already a patch. Get this committed :)
Comment #15
WolfPlayer commentedI would also like to confirm that this patch fixed our issue too. PLEASE update the next release of ctools to include this patch!!!
Comment #16
osopolarWorks for me too. Please also check follow-up issue which requires the patch of this issue to be applied: #2487095: After applying offset to a multi-value field there should be another check if empty.
Comment #17
damienmckennaComment #18
abaier commentedThank you so much! Patch #8 solved the issue for me too. Nice work.
Comment #19
japerryMarking duplicate per #2336985: ctools_entity_field_content_type_render() unnecessarily alters field deltas. We should continue the discussion there.
Comment #20
MKorostoff commentedComment #21
MKorostoff commentedComment #22
hey_germanoPatch in #8 works for me, too. Thanks!
Comment #23
anup.singh commentedHi,
I am using the latest version of ctools ie 7.x-1.9 which has the patch raised in #2487095 and still the issue is not resolved.
But after applying the Patch #8 it worked for me too. So I am reopening this case and marking it as Reviewed and tested.
Thanks
anup.singh
Comment #24
damienmckenna@anup.singh: This issue was marked as being a duplicate of #2336985: ctools_entity_field_content_type_render() unnecessarily alters field deltas and closed, which means you should use the patch from that issue instead of this one. And no, that patch hasn't been committed either.
Comment #25
Lund commented@damienmckenna: I tried to patch first with the patch from the issue you linked, and it didnt do anything. But after i tried to patch with the patch from this issue, and then it work again. So i think both patches have their uses.
Comment #26
ezoulou commentedpatch in #8 works fine. thanks.
Comment #27
dasha_v commentedConfirming that ctools-offset-rendering-2456327-7.patch (here) is duplicate of the ctools-do_not_change_field_item_deltas-2336985-8.patch.
But unfortunately code change is not committed to the entity module, as proposed solution is to use 2430399-field-default-view-resets-deltas.patch (Drupal core) instead, that is also not committed.
Comment #28
dev.patrick commentedConfirming#8 ctools-offset-rendering-2456327-7.patch. Tried and empty pane started showing content.
Comment #29
Huelfe commentedHad this issue as #13 in display suite with dynamic fields. Patch in #8 works fine.
Comment #30
dasha_v commentedHi DamienMcKenna,
Looks like both referenced issues #2336985: ctools_entity_field_content_type_render() unnecessarily alters field deltas and #2430399: field_default_view() resets delta values due to array_merge() have no progress (not resolved), as it impacts only this ctools/panels specific use case as described in this issue.
Patch #8 is RTBC, so I will re-open this thread and re-attach it (the same patch) updated from latest dev.
Could you please include it into the next ctools release?
Thanks,
Dasha
Comment #31
manali_phadke commentedhttps://www.drupal.org/files/issues/ctools-offset-rendering-2456327-7.patch
This patch has solved the rendering issue of content on the website. Now all the content is properly getting displayed on the site.
Comment #32
manali_phadke commentedPatch in #30 works perfectly. now all the content is properly getting rendered on the site. Previously, all values of a multi-valued field were not rendered in a panel page. If we try to set limit value and skip value in panels content, it ignores both the values and displays only first value. By setting array_splice final parameter to its default, the values are displaying properly.
Comment #33
damienmckennaPlease don't hide all files ;-)
Comment #34
manali_phadke commentedComment #35
dev.patrick commentedDo we have any chances to get it merged in coming weeks?
Comment #36
geek-merlinIS:
> By default, array_splice resets array keys unless, as in this case, the final parameter is set to TRUE. By removing the TRUE parameter and allowing array_slice to reset the keys, the offset and limit will then work as expected.
Wow. In an ideal world, i'd say "Lets find and track down the ugly code that depends on some state of array pointers.". But in the current state of the D7 release cycle, i'd prefer to just get it working.
Looking deeper into the code, this is a regression from a refactoring in #2336985-2: ctools_entity_field_content_type_render() unnecessarily alters field deltas wher code behavior changed. If we agree to fix it here, we shoud combine this patch with patch #2336985-16: ctools_entity_field_content_type_render() unnecessarily alters field deltas and
The keep-pointers=true here must be removed too.
This should be a quite simple reroll.
In the light that this only fixes a regression, reconsidering to low-regression-risk.
Comment #37
mastoll commentedSo, this is not included in the V. 1.13 release?
Comment #38
joelpittetIt's not, this probably needs a test to keep it from regressing.
Comment #39
drupalevangelist commentedThank you dasha_v. I am using the 7.x-1.14 version of this module and #30 saved me. Can you please include this patch to the next release?
Comment #40
dasha_v commentedRe-applying the patch on the latest 1.x branch (after 1.14 release) with the change as per comment from axel.rutz in #36 above.
I have also re-tested and confirming it is working as expected (including reverse).
Please review and consider to be included into 1.15 release.
Comment #41
joelpittetThis needs automated tests to be specific
Comment #42
nikolay shapovalov commentedPatch #40 looks good.
But I agree with @joelpittet we need tests.
Comment #43
kasey_mk commented#40 works for me, thanks!
Comment #44
philyPatch #40 was needed for me using Display Suite dynamic field (which is ctools based) delta offset.
And it works (Drupal 7.69, Dispay Suite 2.16, ctools 1.15)!
Could it be further reviewed and committed?
Edit: patch is still required (and works) using Drupal 7.77 & ctools 1.17
Comment #45
avpadernoAs per comment #41, this needs automated tests.
Comment #46
japerryDrupal 7 is no longer supported, closing.