Download & Extend

Cover image needs alt text

Project:Book Review
Version:4.7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Images need alt text to help visually impaired people. Book review needs the option to display alt text for the cover image.

I ran up a quick change to add alt text:

In bookreview.install after:
cover varchar(255) NOT NULL default '',
Add:
cover_alt tinytext not null,

In function bookreview_insert replace:

<?php
  db_query
("INSERT INTO {bookreview} (nid, booktitle, cover, publisher, copyright, isbn, synopsis, contents, review, pages, price, rating) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", $node->nid, $node->title, $node->cover, $node->publisher, $node->copyright, $node->isbn, $node->synopsis, $node->contents, $node->review, $node->pages, $node->price, $node->rating);
?>

with:
<?php
    db_query
("INSERT INTO {bookreview} (nid, booktitle, cover, cover_alt, publisher, copyright, isbn, synopsis"
       
. ", contents, review, pages, price, rating)"
       
. " VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s'"
       
. ", '%s', '%s', '%s', '%s', %d)",
       
$node->nid, $node->title, $node->cover, $node->cover_alt, $node->publisher, $node->copyright, $node->isbn, $node->synopsis,
       
$node->contents, $node->review, $node->pages, $node->price, $node->rating);
?>

In function bookreview_update replace:

<?php
  db_query
("UPDATE {bookreview} SET booktitle = '%s', cover = '%s', publisher = '%s', copyright = '%s', isbn = '%s', pages = '%s', price = '%s', rating = %d, synopsis = '%s', contents = '%s', review = '%s' WHERE nid = %d", $node->title, $node->cover, $node->publisher, $node->copyright, $node->isbn, $node->pages, $node->price, $node->rating, $node->synopsis, $node->contents, $node->review, $node->nid);
?>

with:
<?php
    db_query
("UPDATE {bookreview} SET booktitle = '%s', cover = '%s', cover_alt = '%s', publisher = '%s', copyright = '%s'"
       
. ", isbn = '%s', pages = '%s', price = '%s', rating = %d, synopsis = '%s', contents = '%s', review = '%s'"
       
. " WHERE nid = %d",
       
$node->title, $node->cover, $node->cover_alt, $node->publisher, $node->copyright,
       
$node->isbn, $node->pages, $node->price, $node->rating, $node->synopsis, $node->contents, $node->review,
       
$node->nid);
?>

In function bookreview_form after:

<?php
  $form
['book_detailed_infos']['cover'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Cover picture'),
   
'#default_value' => $node->cover,
   
'#size' => 60,
   
'#maxlength' => 255,
   
'#description' => t('URL of book cover image.'),
  );
?>

add
<?php
  $form
['book_detailed_infos']['cover_alt'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Cover picture alternate text'),
   
'#default_value' => $node->cover_alt,
   
'#size' => 60,
   
'#maxlength' => 255,
   
'#description' => t('Alternate text for book cover image.'),
  );
?>

In function theme_bookreview_list replace:

<?php
  $sql
= db_rewrite_sql("SELECT b.nid, n.title, b.booktitle, b.cover, b.publisher, b.isbn, b.copyright, b.pages, b.rating FROM {bookreview} b INNER JOIN {node} n ON b.nid = n.nid WHERE n.type = 'bookreview'");
?>

with:
<?php
    $sql
= db_rewrite_sql("SELECT b.nid, n.title, b.booktitle, b.cover, b.cover_alt, b.publisher, b.isbn"
       
. ", b.copyright, b.pages, b.rating FROM {bookreview} b"
       
. " INNER JOIN {node} n ON b.nid = n.nid WHERE n.type = 'bookreview'");
?>

Replace:

<?php
   
if ($node->cover) {
     
$cover = "<img src=\"{$node->cover}\" border=\"0\">";
    }
    else {
     
$cover = '&nbsp;';
    }
?>

with:
<?php
   
if($node->cover)
        {
       
$cover_alt = '';
        if(
$node->cover_alt)
            {
           
$cover_alt = ' alt="' . $node->cover_alt . '"';
            }
       
$cover = '<img src="' . $node->cover . '" border="0"' . $cover_alt . '>';
        }
    else
        {
       
$cover = '&nbsp;';
        }
?>

In function theme_bookreview_content replace:

<?php
 
if($node->cover) {
   
$output .= "    <div class=\"cover\"><img src=\"$node->cover\"></div>\n";
  }
?>

with:
<?php
   
if($node->cover)
        {
       
$cover_alt = '';
        if(
$node->cover_alt)
            {
           
$cover_alt = ' alt="' . $node->cover_alt . '"';
            }
       
$output .= '    <div class="cover"><img src="' . $node->cover . '"' . $cover_alt . '></div>' . "\n";
        }
?>

petermoulding.com/web_architect