the themeing guide should include an explanation of how to set the logo in page.tpl.php

-----

Problem/Motivation

On the theme settings page users can add a new site logo, but cannot change the alternative text, alt attribute, for the logo image. Currently the alt attribute for all Core themes are hard coded into page.tpl.php as "Home", with the exception of Garland, which uses $site_name_and_slogan.

Proposed resolution

Provide a 'logo_alt_text' setting on the theme settings form, and modify Core themes to provide a default for this setting in their .info file.

Remaining tasks

Modify patch in #14

1.Make sure that Logo alternative text #textfield is available even when using default theme logo.
2. Remove default for 'logo_alt_text' from theme_get_settings()
3. Update Core theme .info files to provide setting[logo_alt_text] = default alt text

User interface changes

A new Logo alternative text textfield will be added to the logo section of the theme settings form.

API changes

1. The alt attribute for theme logos should no longer be hard coded into page.tpl.php, but should be printed from $logo_alt_text.
2. Themes should define the default alt text for their logo in the theme .info file using:
settings[logo_alt_text] = Alternative text

Original report by Everett Zufelt

When administrators add a custom logo to any of the core themes they are not able to add a custom alt attribute for the image. By default the alt attribute assigned to the logo image (whether the image is the default theme logo or a custom logo) is the site name.

In order to meet the WCAG 2.0 accessibility guideline images that convey information must be marked up with an appropriate alt attribute. Not all images will require a custom alt attribute, but some will, and the ability to provide this currently does not exist for core themes.

Comments

johnalbin’s picture

By default the alt attribute assigned to the logo image (whether the image is the default theme logo or a custom logo) is the site name.

To clarify, that's only true in Garland. Stark uses "Home" as the logo's alt text.

sun.core’s picture

Version: 7.x-dev » 8.x-dev
joachim’s picture

Version: 8.x-dev » 7.x-dev
Category: feature » bug

I think for an interim measure, we can consider this a bug to be fixed:

- all core themes should have the same alt attribute for the logo
- this should be something more descriptive such as 'logo for $sitename' or '$sitename logo'. (see #787634: Site title is read three times with VoiceOver in Garland. for more background on this)

Let's get this fixed, and then move the provision of a custom alt attribute to D8.

Everett Zufelt’s picture

Version: 7.x-dev » 8.x-dev
Category: bug » feature

@joachim

Thanks for taking interest in this. But I think that you should file separate issues against the core themes which need to have their alt text modified.

mgifford’s picture

StatusFileSize
new49.02 KB

So you're looking to add something like this to the system_theme_settings() function of modules/system/system.admin.inc?

     $form['logo']['settings']['logo_alt_text'] = array(
       '#type' => 'textfield',
       '#title' => t('Alternative text for to custom logo'),
       '#default_value' => $logo_alt_text,
       '#description' => t('A description of the custom logo if it conveys meaning. Otherwise it will assume the site name.'),
     );

I added it to line 544 and attached a screenshot for review.

mgifford’s picture

Can this be brought into D7 using the Accessible Helper Module?

Everett Zufelt’s picture

Category: feature » bug

Not a feature request, but a bug. We provide a UI through which a logo can be applied to a site, but do not provide a UI through which an appropriate alt attribute can be set for the logo.

bowersox’s picture

The solution in #5 looks good. Then we would make a 1-line change in Garland page.tpl.php and other themes to apply that ALT attribute.

anou’s picture

Hello,
Still not in core. Should be I think. It's good for accessibility.

andrewmacpherson’s picture

We discussed this at the DrupalCon London Accessibility BoF - http://groups.drupal.org/node/168744/

I did some work towards this for a D6 module which I never brought to full project status. I'll dig it out as a sandbox project.

Everett Zufelt’s picture

@Andrew

If you don't want to build a full project for D6 you can just write a patch against 8.x-dev and post it here. If you haven't done core patches before let us know and we can guide you through it.

andrewmacpherson’s picture

@Everett
Sure. I'll try to get around to it soon. Still catching with stuff after DC and other travel.

mgifford’s picture

That would be great Andrew, thanks!

Everett Zufelt’s picture

Status: Active » Needs review
StatusFileSize
new5.39 KB

A first pass.

- Extends theme settings form to allow for custom alt text
- Provides a $logo_alt_text variable in template_preprocess_page()
- Changes all themes to use $logo_alt_text

Everett Zufelt’s picture

Only issue that I see that needs to be resolved is that logo_alt_text in theme_get_setting() is always used for the alt text.

So, if someone adds a custom logo with custom alt text, then goes back to using the default logo provided by the theme the alt text stays custom.

Perhaps a test in template_preprocess_page() to test if logo is default.

if default use "Home" or whatever we decide for default alt text.
If custom use theme_get_setting('logo_alt_text)

This also means that contrib themes can use:

mytheme_preprocess_page()

If default logo:

$variables['logo_alt_text'] = "My super awesome theme logo"

else

$variables['logo_alt_text'] = theme_get_setting('logo_alt_text')

Thoughts?

Everett Zufelt’s picture

Self reminder / comments.

Should make logo_alt_text #required

mgifford’s picture

I just took a quick look at the patch & had some questions about $site_name_and_slogan

Could this be used to populate the alt text by default when setting up the page?

It is certainly something that we have to get into D8.

andrewmacpherson’s picture

StatusFileSize
new23.41 KB

Hi,

As mentioned at the London BoF, here is my earlier attempt at implementing this as a D6 module. As far as I can recall, it was in a working state. If you want to try it out, there's a modified version of Stark which included, with the necessary page.tpl.php changes. There are quite a lot of @todo comments, but hopefully you can see where I was going.

Being a module, it's a bit more verbose than the patch, with a hook_form_alter()

It's called logo_attributes, as I was considering use cases for other attributes like the logo' link @title, or even @rel=[start|contents]. (These use-cases are out of scope for this issue.)

@17: Yes, I also wondered about offering site name and slogan as options. (They are commented out in my module.) These could be relevant even if using the logo image provided by the theme. This use case was intended to cover the scenario where the logo was set to display, but the site slogan and site name were not.

Supporting tokens could be another option.

Everett Zufelt’s picture

I'd like to keep discussion of a sensible default in #1270598: Decide on appropriate alt text for default logo. The more options that we wish to offer on the theme settings form, the more cluttered the form becomes, and the less likely that the patch will get committed.

Would love to hear feedback on proposal in #15

Everett Zufelt’s picture

I talked to Jen simmons. She said that it would likely be easier for some themers to set the default alt attribute for their theme's logo in .info, and not in hook_preprocess_page(). I think she's right.

my_theme.info:
....

settings[logo_alt_text] = My cool logo
...

Edit: It appears that if we don't set a default in theme_get_settings(), which is done in the current patch, then theme_get_settings() will get the default from the info file by default.

Everett Zufelt’s picture

Updated summary.

Everett Zufelt’s picture

The only problems I see with using theme.info, instead of hook_preprocess_page() is:

1. You can no longer use a variable like $site_name_and_slogan for the alt text
2. Strings in theme.info are not localizable.

andrewmacpherson’s picture

Re: comment 22

Point 1:
This is not the case. If $logo_alt_text is a template variable, then it can be altered by any module/theme which implements hook_preprocess_page(), and changed to whatever the developer/themer chooses.

There's also no reason why we couldn't offer the $site_name (and/or slogan) as an option in the theme settings form. So it could be a choice of:

  • Use the Site Name
  • Use the Site Name and Slogan
  • Use the alternative text provided by the theme
  • Use custom alternative text

This sort-of echoes the current options for the logo and favicon images, with the main difference that we probably don't not want to offer a 'none' value for $logo_alt_text.

I don't necessarily think that all of these options should be in core; extra use-cases could be handled by contrib modules. It would require little more than hook_form_alter() and hook_preprocess_page().

Point 2:
I agree that's a problem, but in a wider context than $logo_alt_text. String localization in themes could be a powerful feature in general. It's worth raising this with the localization and configuration folks.

andrewmacpherson’s picture

Re: comment #15

So, if someone adds a custom logo with custom alt text, then goes back to using the default logo provided by the theme the alt text stays custom.

Is it necessary to couple the custom alt text to the custom logo option? Are there any use-cases for choosing the logo provided by the theme, but overriding the theme-provided alt text with custom alt text?

Use of $site_name could be one. Another would a workaround to translate the theme-provided alt text.

andrewmacpherson’s picture

Re: comment 6

I'd be happy to do some more work towards a D7 version of this, either as a sub-module for the accessible helper project, or as a separate project. The momentum for getting this in core has rekindled my enthusiasm for a contrib module :-)

One problem, as I see it, is that my D6 module in #18 doesn't work out-of-the-box;. It requires a change to page.tpl.php

So if a site-builder has the logo_alt module enabled, and uses a theme from drupal.org contrib, they'll hit a brick-wall WTF unless they know how to change the page template. The best we can really do is provide thorough set-up documentation and/or raise awareness of the feature.

Having said that, I appreciate that the accessible helper modules goals include serving as a demonstration.

andrewmacpherson’s picture

Status: Needs review » Needs work

I'm doing the #d5dChallenge, so I spent time on this today.

After a bit of messing around, I came up with an approach for the problem in comment #15, keeping it all in theme_get_setting(). We can treat it more like the way the favicon path is generated. Store logo_custom_alt_text from the form, the test toggle_logo and default_logo to decide whether to return the custom text from the form, the default text from the theme, or Home.

My code needs a tidy, so I'll aim to post a patch tomorrow evening.

Everett Zufelt’s picture

I postponed #1270598: Decide on appropriate alt text for default logo pending this issue being resolved.

The proposed solution in is to set the default logo alt to $site_name, so this issue needs to take that into account when developing the method of allowing themes to set their own default logo alt and allowing users to override on the theme settings form.

andrewmacpherson’s picture

Status: Needs work » Needs review
StatusFileSize
new8.31 KB

Another patch. Here's my take on things.

Status: Needs review » Needs work

The last submitted patch, logo-custom-alt-717708-28.patch, failed testing.

Everett Zufelt’s picture

@andrewmacpherson

Before I dig into your patch too far, I'm wondering if you might have time to address the test notices?

andrewmacpherson’s picture

StatusFileSize
new8.33 KB

re-rolled patch, minor changes from comment 28.

Needs testing with settings provided by base themes.
Also I'd like to know what people think of the UI strings.

Everett Zufelt’s picture

Status: Needs work » Needs review

bots?

dcmouyard’s picture

Status: Needs review » Needs work

The UI strings look good to me.

When specifying a Logo alternative text source and saving the form, the option gets shown as Site name when finished instead of what was chosen.

Creating a custom alt text and saving the form replaces the alt text correctly in the theme. Editing a theme's .info file to set a custom alt text and choosing Default alternative text provided by the theme, however, does not get applied correctly in the theme.

droplet’s picture

+++ b/includes/theme.inc
@@ -1148,6 +1148,8 @@ function theme_get_setting($setting_name, $theme = NULL) {
+      'logo_alt_custom_text'             =>  '',
       'default_favicon'                  =>  1,

@@ -1177,6 +1179,13 @@ function theme_get_setting($setting_name, $theme = NULL) {
+        if (!empty($themes[$theme_key]->info['settings']['logo_alt_text'])) {

can it either use logo_alt_text or logo_alt_custom_text

2 days to next Drupal core point release.

andrewmacpherson’s picture

Status: Needs work » Needs review

#31: logo-custom-alt-717708-31.patch queued for re-testing.

mgifford’s picture

I could use some clarification about logo_alt_text & logo_alt_custom_text too.

@andrewmacpherson this was introduced in the patch in #31 but would be good to have a bit more clarification on how it's used.

Jeff Burnz’s picture

Why not use theme_image()?

mgifford’s picture

Issue tags: -Accessibility

#31: logo-custom-alt-717708-31.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Accessibility

The last submitted patch, logo-custom-alt-717708-31.patch, failed testing.

mgifford’s picture

Status: Needs work » Closed (won't fix)

This issue hasn't received consensus. Will re-open if someone wants to submit a new patch for review. It's a difficult use case where it is difficult to find where there is a good use case.

Everett Zufelt’s picture

Component: theme system » documentation
Category: bug » task
Status: Closed (won't fix) » Active

We should probably make sure that the method of providing custom alt text for a logo is documented.

jhodgdon’s picture

Where do you think the method for providing alt/title text needs to be documented? I'm assuming that the functions that were updated in this issue were documented properly in the API documentation, so probably you mean that some on-line Community Documentation pages need to be updated?

If so, the best thing to do is probably to either edit them directly, or leave this issue open in the Theme system component with status "needs work" and tag "needs documentation" until that is done.

andrewmacpherson’s picture

Component: documentation » theme system
Status: Active » Needs work
Issue tags: +Needs documentation

The patch doesn't include any API documentation yet.

The logo_alt_custom_text setting was silly idea (just to get it working). Really it should just be logo_alt_text.

I recall having trouble with the internals of theme_get_setting(). Due to the way it sets up an array of theme settings, a custom alt text would end up over-writing the text from a theme (or base theme). I tried a few ways, and none of them were pretty. It might be a good candidate for the clean-up initiative.

I'll try to find time to re-roll this soon. The current patch is from the days before /core directory anyways.

Everett Zufelt’s picture

The accessibility maintainers have decided that this issue is won't fix. We do, however, think that the themeing guide should include an explanation of how to set the logo in page.tpl.php (or wherever it is stored).

jhodgdon’s picture

Title: Custom logo requires custom alt attribute in core themes » Document how to set logo in theme with proper alt tags
Project: Drupal core » Documentation
Version: 8.x-dev »
Component: theme system » Missing documentation
Issue tags: -Needs documentation +theming

In that case, I am moving this to the Documentation issue queue.

mgifford’s picture

I can't recall if we'd decided that this issue here was also a won't fix - #1270598: Decide on appropriate alt text for default logo - would be good to either fix it or mark it closed.

mgifford’s picture

Issue summary: View changes

Updated summary

mgifford’s picture

Issue summary: View changes
Status: Needs work » Active

There's no code to review, just documentation to write.

minneapolisdan’s picture

Status: Active » Needs review

I created documentation over in Drupal theming, https://drupal.org/node/2281499. Does that resolve this issue?

mgifford’s picture

Status: Needs review » Closed (cannot reproduce)

I think it is, thanks! We may open it up in the future, but our decision the last time we looked at it was to deal with it in documentation rather than code.

mgifford’s picture

Status: Closed (cannot reproduce) » Closed (fixed)

wrong closed status.