ManagedFile elements use of arrays for the fids property relies on a quirk of attribute printing to work

Created on 8 January 2025, 21 days ago

Problem/Motivation

In ManagedFile we do this for the current fids value of the element:

$element['fids'] = [
      '#type' => 'hidden',
      '#value' => $fids,
    ];

But $fids is an array.
This only works because of a quirk in twig rendering because of

Drupal\Core\Template\AttributeArray::__toString

This limits the ability to perform programmatic submissions of forms with managed file elements because FormStateInterface::getValues() returns an array for the value, but \Drupal\file\Element\ManagedFile::valueCallback expects the value to be a string imploded with ' '

Steps to reproduce

Proposed resolution

Relax \Drupal\file\Element\ManagedFile::valueCallback to only run explode if the value is a string.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

file.module

Created by

πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024