Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make alt text required when uploading images using media widget (Drupal)
/**
* Implements hook_form_FORM_ID_alter().
*/
function mymodule_form_file_entity_add_upload_alter(&$form) {
_mymodule_media_form_alter($form);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function mymodule_form_file_entity_edit_alter(&$form) {
_mymodule_media_form_alter($form);
}
/**
* Alter the title and description of the alt text field and make it required.
*/
function _mymodule_media_form_alter(&$form) {
$form['field_file_image_alt_text'][LANGUAGE_NONE][0]['value']['#required'] = 1;
$form['field_file_image_alt_text'][LANGUAGE_NONE][0]['value']['#title'] = t('File description (alt text)');
$form['field_file_image_alt_text'][LANGUAGE_NONE][0]['value']['#description'] = t('A useful description of the file so it can be found again and is also required for accessibility');
}
@seamuscampbell

This comment has been minimized.

Copy link

@seamuscampbell seamuscampbell commented Aug 11, 2016

In which file(s) would we have to put this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.