Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide alt text configuration options for images. #1037

Merged
merged 11 commits into from
Sep 30, 2024
2 changes: 1 addition & 1 deletion admin/themes/default/collections/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<?php foreach (loop('Collection') as $collection): ?>
<tr class="collection<?php if(++$key%2==1) echo ' odd'; else echo ' even'; ?>">
<td class="title<?php if ($collection->featured) { echo ' featured';} ?>">
<?php if ($collectionImage = record_image('collection', 'square_thumbnail', array('role' => 'presentation'))): ?>
<?php if ($collectionImage = record_image('collection', 'square_thumbnail')): ?>
<?php echo link_to_collection($collectionImage, array('class' => 'image')); ?>
<?php endif; ?>

Expand Down
16 changes: 16 additions & 0 deletions admin/themes/default/files/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@
<?php echo link_to($file, 'delete-confirm', __('Delete'), array('class' => 'big red button delete-confirm')); ?>
<?php endif; ?>
<?php fire_plugin_hook("admin_files_panel_buttons", array('view'=>$this, 'record'=>$file)); ?>
<div id="alt-text-form" class="field">
<?php echo $this->formLabel('file-alt-text', __('Alt Text'));?>
<div class="inputs">
<p class="explanation"><?php echo __('Provide a brief description of visual files to screen reader users.'); ?></p>
<?php
echo $this->formTextarea(
'alt_text',
$file->alt_text,
array(
'id' => 'file-alt-text',
'rows' => '5'
)
);
?>
</div>
</div>
<?php fire_plugin_hook("admin_files_panel_fields", array('view'=>$this, 'record'=>$file)); ?>
</div>
</section>
Expand Down
10 changes: 9 additions & 1 deletion admin/themes/default/files/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@
<?php endif; ?>
</div>

<div id="item-metadata" class="panel">
<div id="file-item" class="panel">
<h4><?php echo __('Item'); ?></h4>
<p><?php echo link_to_item(null, array(), 'show', $file->getItem()); ?></p>
</div>

<div id="file-alt-text" class="panel">
<h4><?php echo __('Alt Text'); ?></h4>
<p>
<?php echo metadata($file, 'alt_text'); ?>
</p>
</div>


<div id="file-links" class="panel">
<h4><?php echo __('Direct Links'); ?></h4>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion admin/themes/default/items/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<td class="item-info">

<?php if (metadata('item', 'has files')): ?>
<?php echo link_to_item(item_image('square_thumbnail', array('role' => 'presentation'), 0, $item), array('class' => 'item-thumbnail'), 'show', $item); ?>
<?php echo link_to_item(item_image('square_thumbnail', array(), 0, $item), array('class' => 'item-thumbnail'), 'show', $item); ?>
<?php endif; ?>

<span class="title">
Expand Down
12 changes: 11 additions & 1 deletion application/forms/AppearanceSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public function init()
'class' => 'checkbox',
));


$this->addElement('select', 'file_alt_text_element', array(
'label' => __('File Alt Text Element'),
'description' => __('Default element to use in describing visual files to screen reader users via the image tag\'s alt attribute. This can be overridden using the file form\'s "Alt Text" field.'),
'multiOptions' => get_table_options('Element', null, array(
'record_types' => array('File', 'All'),
'sort' => 'orderBySet')
)
));

$adminThemes = Theme::getAllAdminThemes();
if (count($adminThemes) > 1 && is_allowed('Themes', 'edit')) {
foreach ($adminThemes as &$theme) {
Expand All @@ -102,7 +112,7 @@ public function init()
$this->addDisplayGroup(
array(
'use_square_thumbnail', 'link_to_file_metadata', 'per_page_admin', 'per_page_public',
'show_empty_elements', 'show_element_set_headings',
'show_empty_elements', 'show_element_set_headings', 'file_alt_text_element',
),
'display-settings', array('legend' => __('Display Settings'))
);
Expand Down
20 changes: 20 additions & 0 deletions application/migrations/20240917160000_addFileAltText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Omeka
*
* @copyright Copyright 2007-2022 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* Add alt text column to file table
*
* @package Omeka\Db\Migration
*/
class addFileAltText extends Omeka_Db_Migration_AbstractMigration
{
public function up()
{
$this->db->query("ALTER TABLE {$this->db->File} ADD `alt_text` mediumtext collate utf8_unicode_ci");
}
}
31 changes: 31 additions & 0 deletions application/models/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ class File extends Omeka_Record_AbstractRecord implements Zend_Acl_Resource_Inte
*/
public $metadata;

/**
* Alt text to use for file display.
*
* @var string
*/
public $alt_text;

/**
* Folder paths for each type of files/derivatives.
*
Expand Down Expand Up @@ -149,11 +156,35 @@ public function getProperty($property)
return $this->getDisplayTitle($this->original_filename);
case 'rich_title':
return $this->getRichTitle(html_escape($this->original_filename));
case 'alt_text':
return $this->getAltText();
default:
return parent::getProperty($property);
}
}

public function getAltText() {
zerocrates marked this conversation as resolved.
Show resolved Hide resolved
$fileCustomAltText = $this->alt_text;
$fileAltTextElementId = get_option('file_alt_text_element');

if ($fileCustomAltText) {
return $fileCustomAltText;
} elseif ($fileAltTextElementId) {
$fileAltTextElement = $this->getElementById($fileAltTextElementId);
$fileAltTextElementTexts = $this->getElementTextsByRecord($fileAltTextElement);
if ($fileAltTextElementTexts) {
$fileAltTextElementText = $fileAltTextElementTexts[0]->text;
if ($fileAltTextElementTexts[0]->html) {
$fileAltTextElementText = strip_formatting($fileAltTextElementText);
$fileAltTextElementText = html_entity_decode($fileAltTextElementText, ENT_QUOTES, 'UTF-8');
}
return trim($fileAltTextElementText);
}
} else {
return '';
}
}

/**
* Initialize the mixins.
*/
Expand Down
1 change: 1 addition & 0 deletions application/schema/files.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%files` (
`added` timestamp NOT NULL DEFAULT '2000-01-01 00:00:00',
`stored` tinyint(1) NOT NULL default '0',
`metadata` mediumtext collate utf8_unicode_ci NOT NULL,
`alt_text` mediumtext collate utf8_unicode_ci,
PRIMARY KEY (`id`),
KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
12 changes: 2 additions & 10 deletions application/views/helpers/FileMarkup.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,18 +636,10 @@ public function image_tag($record, $attrs, $format)
$alt = '';
if (isset($attrs['alt'])) {
$alt = $attrs['alt'];
} elseif ($fileTitle = metadata($file, 'display title', array('no_escape' => true))) {
$alt = $fileTitle;
}
$attrs['alt'] = $alt;

$title = '';
if (isset($attrs['title'])) {
$title = $attrs['title'];
} else {
$title = $alt;
$alt = $file->getAltText();
}
$attrs['title'] = $title;
$attrs['alt'] = $alt;

$attrs = apply_filters('image_tag_attributes', $attrs, array(
'record' => $record,
Expand Down
2 changes: 1 addition & 1 deletion application/views/scripts/items/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="item-meta">
<?php if (metadata('item', 'has files')): ?>
<div class="item-img">
<?php echo link_to_item(item_image(null, array('role' => 'presentation'))); ?>
<?php echo link_to_item(item_image(null)); ?>
</div>
<?php endif; ?>

Expand Down
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// Define the current version of Omeka.
define('OMEKA_VERSION', '3.2-dev3');
define('OMEKA_VERSION', '3.2-dev4');

// Define the application environment.
if (!defined('APPLICATION_ENV')) {
Expand Down