Last active
December 24, 2015 00:09
-
-
Save jeremyboggs/6714995 to your computer and use it in GitHub Desktop.
Use DC:Description on File record for alt attribute in Omeka 2.x.
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
<?php | |
/** | |
* Use the DC: Description field on a File record for an image's alt attribute. Add this snippet to | |
* a plugin or to your theme's custom.php file. | |
* | |
* See https://github.com/omeka/Omeka/blob/master/application/views/helpers/FileMarkup.php#L744-751 | |
* for parameters available to the file_markup filter. | |
* | |
* See https://github.com/omeka/Omeka/blob/master/application/views/helpers/FileMarkup.php#L619-647 | |
* for details of what Omeka_View_Helper_FileMarkup::derivativeImage outputs. | |
**/ | |
function add_file_description_alt($html, $params) { | |
if ($params['callback'] == 'derivativeImage') { | |
// Set the alt attribute to DC:Description field on the File record. | |
$params['options']['imgAttributes']['alt'] = metadata($params['file'], array('Dublin Core', 'Description'), array('snippet' => 100)); | |
// Create a new FileMarkup helper to reconstruct our HTML. | |
$helper = new Omeka_View_Helper_FileMarkup; | |
// Specifically set HTML based on callback in Omeka_View_Helper_FileMarkup. | |
$html = $helper->derivativeImage($params['file'], $params['options']); | |
// Copy/paste wrapper from Omeka_View_Helper_FileMarkup::fileMarkup. | |
$wrapperAttributes = $params['wrapper_attributes']; | |
$wrapper = !empty($wrapperAttributes) ? '<div ' . tag_attributes($wrapperAttributes) . '>' : ''; | |
$html = !empty($wrapper) ? $wrapper . $html . "</div>" : $html; | |
} | |
return $html; | |
} | |
add_filter('file_markup', 'add_file_description_alt'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment