- πΊπΈUnited States japerry KVUO
8.x-1.x is now EOL, which ran on the WebDam/Bynder platform.
On asset update from the DAM there is no ability to hook and change 'alt' text for an image file
A DAM should manage aspects of a file including alt text. hook_entity_type_presave() triggers on first file import and creation but not on update of the file.
Motivation
Alt text is important for accessibility.
It is double work to edit a file in both the DAM and in Drupal.
First. Based on https://www.drupal.org/project/media_acquiadam/issues/3048225 π¬ Missing alt and title HTML image properties Closed: won't fix I created a simple module to set the alternate text of an image.
/**
* Implements hook_ENTITY_TYPE_presave().
*/
function REDACTED_media_presave(MediaInterface $entity) {
/** @var \Drupal\media\MediaInterface $source */
$source = $entity->getSource();
if ('acquiadam_asset' == $source->getPluginId()) {
/** @var \Drupal\media_acquiadam\MediaEntityHelper $media_helper */
$media_helper = \Drupal::service('media_acquiadam.asset_media.factory')
->get($entity);
$asset = $media_helper->getAsset();
// Set the image alt attribute based on available Asset metadata.
if (!empty($asset)) {
/** @var \Drupal\image\Plugin\Field\FieldType\ImageItem $field */
$field = $entity->get('field_asset')->first();
$field->set('alt', $asset->description);
}
}
}
Next, link a new file from the dam and trigger import.
Third, update the description field in the DAM for the image and trigger asset update with cron run. Presave hook does not trigger
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
8.x-1.x is now EOL, which ran on the WebDam/Bynder platform.