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

Command icon 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

damienmckenna created an issue. See original summary.

damienmckenna’s picture

Issue summary: View changes
damienmckenna’s picture

Assigned: Unassigned » damienmckenna

  • damienmckenna committed 3861f84d on 8.x-2.x
    Issue #3618555 by DamienMcKenna: Optionally save meta data to the image...
damienmckenna’s picture

Title: Provide setting to save meta tag as "alt" value on uploaded images » Provide option to save meta tag as "alt" value on uploaded images
damienmckenna’s picture

Assigned: damienmckenna » Unassigned
Status: Active » Fixed

Done.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.