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.
I've been trying for a while now to alter the Description form field that appears after a file has been uploaded. Basically I just want to give the field a different #title and add a #description, but I can't seem to get it. The form alter function works otherwise for other form elements, so maybe it's just my targeting. Used dpm() to try and sort it out, but no luck.
Here's what I have now:
$form['field_document_file']['0']['data']['description']['#title'] = t('Document Title');
$form['field_document_file']['0']['data']['description']['#description'] = t('Enter a document title.');
Any help would be greatly appreciated, I need to do this for a couple of upcoming projects as well.
Thanks
Comments
Comment #1
quicksketchYou can't get at these field through hook_form_alter() directly because they are added in #process functions (after hook_form_alter() runs). In order to modify these "sub fields" you need to add your own #process function to the field, then modify the field in that process callback. I suggest looking at modules like ImageField Extended for an example of how to do this. I do not provide coding support in the issue queue, so you'll have to take it from there.