-
-
Save delineas/1e55c9cb911e631174a93726b553d45e to your computer and use it in GitHub Desktop.
Make alt text required when uploading images using media widget (Drupal)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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