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.

Comments

davidrf’s picture

StatusFileSize
new860 bytes

Status: Needs review » Needs work

The last submitted patch, 1: ctools-offset-rendering-2456327-1-D7.patch, failed testing.

davidrf’s picture

This was my first patch contribution ever, so any guidance as to why the patch failed testing would be greatly appreciated.

davidrf’s picture

StatusFileSize
new724 bytes

Resubmitting the patch (modified).

davidrf’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: ctools-offset-rendering-2456327-4-D7.patch, failed testing.

kcolwell’s picture

Thanks... 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.

kepford’s picture

Status: Needs work » Needs review
StatusFileSize
new696 bytes

Thanks 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!

damienmckenna’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Assigned: davidrf » Unassigned

Thanks for the patch, davidrf!

FYI don't set the "assigned" to yourself unless you're specifically working on it.

christoph’s picture

I 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:-

  if (isset($conf['delta_limit'])) {
    $offset = intval($conf['delta_offset']);
    $limit = !empty($conf['delta_limit']) ? $conf['delta_limit'] : NULL;
    $all_values = array_slice($all_values, $offset, $limit, FALSE); //Changing to FALSE to reset keys
  }

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:-

if (isset($variables['element'])) {
  $keys = element_children($variables['element']);
  $element = $variables['element'];
  if (isset($items) && count($items) < count($keys)) {
    $items = array();
    foreach ($keys as $delta => $key) {
      $items[$key] = $element[$key];
    }
  }
}

This corrects the key issue we were having. I hope this helps in the mean time as the root cause if solved.

davidrf’s picture

cristoph - 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!

jkopel’s picture

I just ran into this when updating a site from 1.5 - 1.7 and #8 worked well for me.
Nice job @davidrf, thanks!

kutulus’s picture

Hi,
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.

Sneakyvv’s picture

Status: Needs review » Reviewed & tested by the community

I'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 :)

WolfPlayer’s picture

I would also like to confirm that this patch fixed our issue too. PLEASE update the next release of ctools to include this patch!!!

osopolar’s picture

Works 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.

damienmckenna’s picture

abaier’s picture

Thank you so much! Patch #8 solved the issue for me too. Nice work.

japerry’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Marking duplicate per #2336985: ctools_entity_field_content_type_render() unnecessarily alters field deltas. We should continue the discussion there.

MKorostoff’s picture

Title: Multi-value field offset not working correctly when panel panes are rendered » MKorostoff
MKorostoff’s picture

Title: MKorostoff » Multi-value field offset not working correctly when panel panes are rendered
hey_germano’s picture

Patch in #8 works for me, too. Thanks!

anup.singh’s picture

Status: Closed (duplicate) » Reviewed & tested by the community

Hi,

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

damienmckenna’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Parent issue: #2423731: Plan for CTools 7.x-1.8 release »
Related issues: +#2336985: ctools_entity_field_content_type_render() unnecessarily alters field deltas

@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.

Lund’s picture

@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.

ezoulou’s picture

patch in #8 works fine. thanks.

dasha_v’s picture

Confirming 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.

dev.patrick’s picture

Confirming#8 ctools-offset-rendering-2456327-7.patch. Tried and empty pane started showing content.

Huelfe’s picture

Had this issue as #13 in display suite with dynamic fields. Patch in #8 works fine.

dasha_v’s picture

Status: Closed (duplicate) » Reviewed & tested by the community
StatusFileSize
new734 bytes

Hi 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

manali_phadke’s picture

https://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.

manali_phadke’s picture

Patch 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.

damienmckenna’s picture

Please don't hide all files ;-)

manali_phadke’s picture

dev.patrick’s picture

Do we have any chances to get it merged in coming weeks?

geek-merlin’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +low-regression-risk

IS:
> 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

+++ b/plugins/content_types/entity_context/entity_field.inc
@@ -127,33 +127,19 @@ function ctools_entity_field_content_type_render($subtype, $conf, $panel_args, $
+    $all_values = array_reverse($all_values, TRUE);

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.

mastoll’s picture

So, this is not included in the V. 1.13 release?

joelpittet’s picture

Issue tags: +Needs tests

It's not, this probably needs a test to keep it from regressing.

drupalevangelist’s picture

Thank 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?

dasha_v’s picture

Status: Needs work » Needs review
StatusFileSize
new975 bytes

Re-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.

joelpittet’s picture

Status: Needs review » Needs work

This needs automated tests to be specific

nikolay shapovalov’s picture

Patch #40 looks good.
But I agree with @joelpittet we need tests.

kasey_mk’s picture

#40 works for me, thanks!

phily’s picture

Status: Needs work » Patch (to be ported)

Patch #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

avpaderno’s picture

Status: Patch (to be ported) » Needs work

As per comment #41, this needs automated tests.

japerry’s picture

Status: Needs work » Closed (outdated)

Drupal 7 is no longer supported, closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.