Skip to content

Regression: Multiupload when uploading more than allowed - TypeError when saving node #7119

@indigoxela

Description

@indigoxela

Description of the bug

Validation in file_field_widget_multiple_count_validate() does not work properly.

It should prevent too many field items, if a restriction via field cardinality exists on node (entity) save. It doesn't. Instead it causes a fatal error.
Same problem when selecting more than allowed from image library.

Steps To Reproduce

  1. Attach an image field to a node
  2. Set a limit on image count (field cardinality > 1, but < unlimited)
  3. Open the node form and upload images, more than allowed

Alternative way to trigger:

  1. Attach an image field to a node
  2. Set a limit on image count (field cardinality > 1, but < unlimited)
  3. Create a node with that amount of images (adhere max)
  4. Go to admin/structure/types/manage/NODE_TYPE/fields/field_SOMETHING and lower the limit
  5. Open that node form again and save without any changes

Another way to trigger:

  1. Attach an image field to a node
  2. Set a limit on image count (field cardinality > 1, but < unlimited), make sure the image browser's enabled
  3. Open the node form
  4. Open the image library dialog and add limit - 1 images
  5. Open the image lib again and add as many as possible (more than allowed in field, only until Follow-up: Selecting multiple images from library allows too many items #7122 is resolved)

Actual behavior

You can upload more images than field cardinality allows. They show up in the field list in that form.

Now try to save the node.

TypeError: array_slice(): Argument #1 ($array) must be of type array, string given in array_slice() (line 1049 of ...core/modules/file/file.field.inc). 

Expected behavior

I shouldn't even have come to that point (too many images), but that's a topic on its own.
Saving the node should definitely not end up with a TypeError. 😬

Additional information

Initially it thought, it's related to the dimension limit, but the actual problem is how form_state values get handled.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions