Problem/Motivation
Separate to how Field API will be used for storing values on media items (#3618058: Save image meta data to fields using DropzoneJS), there needs to be a way of saving a meta tag to the "alt" text on uploaded images.
This is some prototype code:
/**
* Implements hook_form_alter().
*/
function MYMODULE_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'media_image_add_form') {
$values = $form_state->getValues();
if (!empty($values['field_media_image'][0]['fids'][0])) {
if (empty($form['field_media_image']['widget'][0]['#default_value']['alt'])) {
$file = File::load($values['field_media_image'][0]['fids'][0]);
$exif_content = new ExifContent();
$metadata = $exif_content->getDataFromFileUri($file->getFileUri());
if (!empty($metadata['iptc']['object_name'])) {
$form['field_media_image']['widget'][0]['#default_value']['alt'] = $metadata['iptc']['object_name'];
}
}
}
}
}
That saves the IPTC Object Name value as the alt text on the image. A setting will be provided to control this.
Proposed resolution
Provide a global setting to select a meta tag to assign to an image's "alt" text when it is uploaded.
Remaining tasks
Build a setting to control which meta tag is saved.
Update the logic above.
User interface changes
A setting is available to control which meta tag is saved as the "alt" text on uploaded files.
API changes
TBD
Data model changes
n/a
Issue fork exif-3618555
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
damienmckennaComment #3
damienmckennaComment #6
damienmckennaComment #7
damienmckennaDone.