See https://www.drupal.org/node/2621528#comment-10859088

If you create a paragraph and inside the paragraph entity type a field which is an image field that allows not 1 and not an unlimited number of items the values inside validateMultipleCount are not found.

This is easily fixable with a change to the function:

FileWidget::validateMultipleCount line 338:

    $current = count(Element::children(NestedArray::getValue($form, $parents))) - 1;

to

    $current = count(Element::children(NestedArray::getValue($form_state->getValues(), $parents))) - 1;

It looks like it is only used for the counter.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danielbeeke created an issue. See original summary.

danielbeeke’s picture

miro_dietiker’s picture

Status: Active » Needs review
swentel’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

The last submitted patch, 2: get-counter-values-inside-subform-2669326-2.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jmuzz’s picture

This also affects the field collection module.

I agree with the proposed fix. The problem seems to be a mixup between #parents and #array_parents. For example, for field collections, the following change will also work:

    $parents = $element['#parents'];
    $values = NestedArray::getValue($form_state->getValues(), $parents);

    // Add the following line:
    $parents = $element['#array_parents'];

    array_pop($parents);
    $current = count(Element::children(NestedArray::getValue($form, $parents))) - 1;
Xano’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
6.36 KB

The original patch does not work, because it tries to get the child elements from form state values, which is impossible.

This patch tries to stay as close as possible to the original solution (because I did not want to dig through the array structures, not because I think we necessarily must). It also fixes the test failures. It seems the original error handling and its test coverage was not very good, unless I missed something.

Sutharsan’s picture

The patch works in my situation:
- Node with Paragraph field of Paragraph type with (text and) image field with 3 values.

Initial work around was to make the image field cardinality unlimited.

johnchque’s picture

Tested manually and works fine with the patch! Let's see what happens with the test only patch. :)

Status: Needs review » Needs work

The last submitted patch, 10: filewidget_inside-2669326-10-test-only.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review

Cool, then this fixes the problem I think

kasperg’s picture

Status: Needs review » Reviewed & tested by the community

I tested #8 on 8.1.3 and it works as well. I reviewed the code and it and looks good to me.

xjm’s picture

Title: FileWidget inside subform can't find it's values » FileWidget inside subform can't find its values
FileSize
6.36 KB

Thanks for providing a test-only patch!

Due to a quirk of the testing system, we need to make sure that the actual patch is the final attachment (otherwise it does not get automatically retested). So reuploading that, and saving issue credit.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 14: drupal_2669326_8.patch, failed testing.

The last submitted patch, 14: drupal_2669326_8.patch, failed testing.

Xano’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC as per #13.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 14: drupal_2669326_8.patch, failed testing.

Xano’s picture

Status: Needs work » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!

  • catch committed 57c7fdd on 8.2.x
    Issue #2669326 by danielbeeke, Xano, yongt9412, swentel, jmuzz,...

  • catch committed 3aabab6 on 8.1.x
    Issue #2669326 by danielbeeke, Xano, yongt9412, swentel, jmuzz,...

  • catch committed 57c7fdd on 8.3.x
    Issue #2669326 by danielbeeke, Xano, yongt9412, swentel, jmuzz,...

  • catch committed 57c7fdd on 8.3.x
    Issue #2669326 by danielbeeke, Xano, yongt9412, swentel, jmuzz,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.