Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The description's text in the description field in the file field cannot be changed.
This is because at the fileWidget.php we have this:
// Add the description field if enabled.
if ($element['#description_field'] && $item['fids']) {
$config = \Drupal::config('file.settings');
$element['description'] = array(
'#type' => $config->get('description.type'),
'#title' => t('Description'),
'#value' => isset($item['description']) ? $item['description'] : '',
'#maxlength' => $config->get('description.length'),
'#description' => t('The description may be used as the label of the link to the file.'),
);
}
Which basically overwrite any possible value in the description form.
Proposed resolution
Before to just overwrite the $element['description']
let's check if it already exists and if that is the case then merge the values.
Remaining tasks
- Write patch
- Write a test
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
description-description.png | 21.16 KB | gnuget |
Comments
Comment #2
gnugetOk, After to work on this for a few hours I found how to do it.
basically, the description field is build in a
#process
callback so we need to add another callback. something like this: