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');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment