Problem/Motivation

When I add logo img to sites I don't get a ALT && Title field as I would get when adding an image_field to nodes.

Proposed resolution

Thus, it seems there is no simple GUI way to add these; By now I myself added them through the twig, but I humbly suggest adding these fields as ensuring valid usage of Drupal for all users. Also, they're quite important for SEO.

Sending people to add these from at the SQL or by an external module should be avoided, I think.

Remaining tasks

The tests that were added need reviewing by someone experienced with tests.

We still need to decide whether we should reference the newly created variables in the twig templates or just stick with the markup defined in variables content ie:

Option 1 (current patch):

$variables['site_logo_alt'] = $variables['content']['site_logo_alt']['#markup'];
$variables['site_logo_title'] = $variables['content']['site_logo_title']['#markup'];

Versus Option 2 (proposed in #23, saying we should maybe not create new variables, and just reference the markup from the existing $variables['content'])

$variables['content']['site_logo_alt']['#markup'];
$variables['content']['site_logo_title']['#markup'];

In #30 it's suggested that using option 1 is okay. Option 1 makes it so we lose the #access part of the render array. If you look at other variables like 'site_name', and 'site_slogan', they do not have the #access part of the render array. Here's an example of some other variables that don't have #access:

'site_logo' => string(35) "/drupal/core/themes/bartik/logo.svg"
'site_logo_alt' => string(0) ""
'site_logo_title' => string(0) ""
'site_name' => string(6) "Drupal"
'site_slogan' => string(0) ""

Completed Tasks

Configuration for the logo alt attribute and title attribute has been added in two cases:
1) When you use the default logo
2) When you upload your own custom logo

The system branding block has been updated to support the logo alt and logo title attributes in the Bartik, Classy and Stable themes.

Testing for saving the alt attribute and title attribute has been added in a patch in https://www.drupal.org/node/2780293#comment-12061662 (#40). Testing to ensure the alt and title attributes show in the branding block have been added in patch https://www.drupal.org/node/2780293#comment-12073031 (#45)

@rovo: has tested accessibility via Wave in #34

CommentFileSizeAuthor
#168 2780293-nr-bot.txt147 bytesneeds-review-queue-bot
#164 2780293-159-1.patch17.44 KBbharti mehta
#159 interdiff-2780293-158-159.txt2.62 KBguptahemant
#159 2780293-159.patch17.44 KBguptahemant
#158 2780293-158.patch16.9 KBmanuel garcia
#158 interdiff-2780293-154-158.txt3.91 KBmanuel garcia
#154 2780293-154.patch13.09 KBandrewmacpherson
#154 interdiff.2780293.153-154.txt3.31 KBandrewmacpherson
#153 interdiff.2780293.151-153.txt15.02 KBandrewmacpherson
#153 2780293-153.patch13.1 KBandrewmacpherson
#151 interdiff-2780293-146-151.txt1.14 KBandrewmacpherson
#151 2780293-151.patch17.6 KBandrewmacpherson
#146 interdiff_142-146.txt726 bytesaleevas
#146 2780239-146.patch18.62 KBaleevas
#145 interdiff_142-145.txt726 bytesaleevas
#145 2780239-145.patch21.59 KBaleevas
#142 interdiff_141-142.txt1.75 KBshaal
#142 core-theme-add-logo-gui-2780293-142.patch21.41 KBshaal
#141 interdiff_122-141.txt2.62 KBvacho
#141 2780293-141.patch19.52 KBvacho
#139 interdiff_122-136.txt2.67 KBvacho
#136 2780293-136.patch19.31 KBsonu.raj.chauhan
#135 2780293-135.patch19.24 KBsonu.raj.chauhan
#133 2780293-124.patch19.3 KBsonu.raj.chauhan
#132 2780293-123.patch19.27 KBsonu.raj.chauhan
#122 2780293-122.patch19.57 KBmanuel garcia
#122 interdiff-2780293-119-122.txt1.84 KBmanuel garcia
#119 2780293-119.patch19.1 KBmanuel garcia
#119 interdiff-2780293-118-119.txt1.22 KBmanuel garcia
#118 2780293-118.patch19.09 KBmanuel garcia
#102 2780293-102.patch18.96 KBmanuel garcia
#102 interdiff-2780293-100-102.txt2.84 KBmanuel garcia
#100 2780293-100.patch19.13 KBmanuel garcia
#100 interdiff-2780293-98-100.txt4.28 KBmanuel garcia
#98 2780293-98.patch18.79 KBmanuel garcia
#98 interdiff-2780293-96-98.txt5.4 KBmanuel garcia
#96 reroll-diff-2780293-89-96.txt5.99 KBmanuel garcia
#96 2780293-96.patch18.57 KBmanuel garcia
#89 2780293-89.patch18.7 KBmanuel garcia
#89 interdiff.txt2.98 KBmanuel garcia
#88 2780293-88.patch16.86 KBmanuel garcia
#87 2780293-87.patch16.89 KBmanuel garcia
#87 interdiff.txt2.29 KBmanuel garcia
#84 2780293-84.patch16.48 KBmanuel garcia
#84 interdiff.txt1.54 KBmanuel garcia
#78 Screenshot from 2017-05-16 11-09-50.png62.64 KBmanuel garcia
#77 Afterpatch.png31.53 KBdinesh18
#77 Before patch.png100.13 KBdinesh18
#75 interdiff-72-75.txt1.21 KBjohn cook
#75 2780293-75.patch15.54 KBjohn cook
#72 interdiff-70-72.txt1.24 KBjohn cook
#72 2780293-72.patch15.64 KBjohn cook
#70 interdiff-63-70.txt1.44 KBjohn cook
#70 2780293-70.patch15.58 KBjohn cook
#63 2780293-63.patch15.46 KBmanuel garcia
#63 interdiff.txt3.36 KBmanuel garcia
#61 2780293-61.patch12.87 KBmanuel garcia
#61 interdiff.txt6.62 KBmanuel garcia
#56 2780293-56.patch12.17 KBmanuel garcia
#56 interdiff.txt1.83 KBmanuel garcia
#55 interdiff.txt1.52 KBpritishkumar
#55 2780293-55.patch12.19 KBpritishkumar
#47 Afterpatch_3.png278.57 KBmahalingam_cs
#47 Afterpatch_2.png19.24 KBmahalingam_cs
#47 Afterpatch_1.png277.95 KBmahalingam_cs
#47 Beforepatch.png37.21 KBmahalingam_cs
#46 logo-settings-new-text.png19.21 KBjamesdixon
#46 bartik-default.png13.31 KBjamesdixon
#46 bartik-custom-logo.png16.04 KBjamesdixon
#45 2780293-45.patch13.07 KBmanuel garcia
#45 interdiff.txt3.28 KBmanuel garcia
#40 interdiff-2780293-22-40.txt827 bytesjamesdixon
#40 2780293-40.patch11.27 KBjamesdixon
#34 WAVE-after-patch.png157.02 KBrovo
#34 WAVE-before-patch.png137.96 KBrovo
#27 2780293-22-reroll.patch10.4 KBjoelpittet
#25 interdiff.txt2.13 KBmanuel garcia
#22 2780293-22.patch10.37 KBjoelpittet
#22 interdiff.txt4.35 KBjoelpittet
#20 2780293-20.patch8.18 KBjoelpittet
#20 interdiff.txt1.23 KBjoelpittet
#15 2780293_logo_image_output.png185.51 KBsteffenr
#15 2780293_logo_image_custom.png45.82 KBsteffenr
#15 2780293_logo_image_default.png22.53 KBsteffenr
#9 2780293-7-ui-alt-title.patch7.8 KBjoelpittet

Issue fork drupal-2780293

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 2780293-add-gui-to Comparecompare

Comments

Benia created an issue. See original summary.

Benia’s picture

Issue summary: View changes
dawehner’s picture

Component: base system » theme system
Issue tags: +Drupalaton

That sounds more like a theme system issue

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Title: No GUI way to add logo img ALT && Title » No GUI way to add logo img alt and title attributes
Issue tags: +a11y, +Usability

This could go in to 8.x, could you provide a patch @Benia?

Benia’s picture

Sadly I have yet to acquire enough PHP-SQL knowledge regarding how to add this feature (I think I could do it in my own site with JS but it certainty not a global solution).

markconroy’s picture

Status: Active » Closed (duplicate)
Issue tags: -a11y +Accessibility

An issue for this has already been discussed and it was decided to provide documentation rather than a patch. See here: https://www.drupal.org/node/717708

Documentation page here: https://www.drupal.org/docs/7/theming/howto/how-to-edit-alt-tag-on-your-... (though it's for Drupal 7 at the moment)

markconroy’s picture

Adding new tag to this issue. Let's get a fresh opinion on this, since the linked issue is over 4 years old.

Andrew? Mike?

joelpittet’s picture

Status: Closed (duplicate) » Needs review
Issue tags: -Accessibility, -Needs accessibility review +a11y, +Needs tests
StatusFileSize
new7.8 KB

Don't need to know SQL, so you are half way. Anyways here's a start, may need some UX review on the labels and we need some tests but it looks to work for me:)

joelpittet’s picture

Issue tags: -a11y +Needs accessibility review, +Accessibility, +Needs UX review

@markconroy I think we can get this in core, sorry cross posted with you.

joelpittet’s picture

Benia’s picture

Issue summary: View changes
yoroy’s picture

Issue tags: +Needs screenshots

Some screenshots so we can review the text labels would be good.

steffenr’s picture

Assigned: Unassigned » steffenr

I'll test it and add some screenshots for the issue.

steffenr’s picture

Assigned: steffenr » Unassigned
StatusFileSize
new22.53 KB
new45.82 KB
new185.51 KB

The patch worked fine for me and adds the mentioned fields to the logo settings form of all the themes.

Attached the screenshots:

Custom image/ Default Image

Output in theme

SteffenR

steffenr’s picture

Issue tags: -Needs screenshots
lauriii’s picture

Status: Needs review » Needs work
+++ b/core/themes/bartik/templates/block--system-branding-block.html.twig
@@ -11,20 +11,22 @@
+    <a href="{{ path('<front>') }}" title="{{ site_logo_title }}" rel="home" class="site-branding__logo">
+      <img src="{{ site_logo }}" alt="{{ site_logo_alt }}" />
...
+          <a href="{{ path('<front>') }}" title="{{ site_logo_title }}" rel="home">{{ site_name }}</a>

Could we use the |default('Home'|t) here so that we don't break this for existing sites? I believe this change could be done also to the Stable and Classy templates since this is a non-breaking change!

yoroy’s picture

Issue tags: -Needs UX review

Thanks for the screenshots. The labels look good. Maybe have a look at the options for an image field, I suspect there's descriptions there that show what an alt, what a title attribute is for.

joelpittet’s picture

@lauriii, we can add |default() twig filter but it shouldn't break existing sites because I added that text in the default configuration settings.

And oh yeah it could go into Stable/Classy, good thinking

joelpittet’s picture

Status: Needs work » Needs review
Issue tags: -Needs manual testing
StatusFileSize
new1.23 KB
new8.18 KB

I've addressed #17 with the #description from core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php:227 and the #maxlength

lauriii’s picture

Status: Needs review » Needs work

@joelpittet the default configuration gets only imported on install so existing installations are affected if we don't use the default filter. Not sure if there should be update hook instead to set the default values.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new4.35 KB
new10.37 KB

Oh that makes sense, thanks for explaining that @lauriii. I did it to all of them.

lauriii’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/system.module
@@ -831,6 +831,14 @@ function system_preprocess_block(&$variables) {
+        $variables['site_logo_alt'] = $variables['content']['site_logo_alt']['#markup'];
...
+        $variables['site_logo_title'] = $variables['content']['site_logo_title']['#markup'];

On this conversion we lose the #access from the render array. We should instead copy the whole render array. I'm not sure if we need to do this at all and could just access the variable inside content?

There's still some needs tags that needs to be also addressed.

bart88’s picture

+++ b/core/includes/theme.inc
@@ -476,6 +476,12 @@ function theme_settings_convert_to_config(array $theme_settings, Config $config)
+    elseif ($key == 'alt') {

Is there a reason this isn't a switch statement?

manuel garcia’s picture

StatusFileSize
new2.13 KB

Re #24 My guess is that the last two don't really qualify for a normal switch statement, though I could be wrong. Attached how it'd look as a switch statement.. not too pretty either.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new10.4 KB

Reroll, #23 needs to be addressed still.

jcnventura’s picture

Version: 8.3.x-dev » 8.4.x-dev
jcnventura’s picture

Issue tags: +dcffm17
jcnventura’s picture

I've just looked at #23, and I don't think it's relevant for this issue, as it '#access' is lost to all other site variables as well. Fixing that to pass the whole render array should be a new issue. But indeed, it needs tests.

melinda_ksz’s picture

I have reviewed and tested the patch for different use cases (adding only alt text, adding only title, adding both, also adding custom logo...), it worked all good.

mradcliffe’s picture

The issue summary should be update to include the status of the issue with regard to what has been done so far and what needs to be done.

- To address a11y review tag the a11y gate should be helpful: https://www.drupal.org/core/gates#accessibility
- The Needs tests tag still seems to apply with the latest patch so that should include testing the new markup in a browser test.

@jcnventura, could you go into more depth about why #23 does not apply?

jamesdixon’s picture

Assigned: Unassigned » jamesdixon

Patch in #27 worked for me. Looking further into #23 and how the issue summary should be updated based on what's been done.

rovo’s picture

StatusFileSize
new137.96 KB
new157.02 KB

I've applied the patch from #27 and tested with WAVE.

WAVE before

WAVE after

jamesdixon’s picture

Assigned: jamesdixon » Unassigned
Issue summary: View changes

Updated the issue summary. Looks like for the implementation part we need to decide whether it's okay #access is not part of the render array for $variables['site_logo_alt'] and $variables['site_logo_title'].

@jcnventura argues that other defined variables like $variables['site_name'] don't have #access, and so $variables['site_logo_alt'] and $variables['site_logo_title'] don't need it.

Also a browser test and accessibility review are still needed.

jamesdixon’s picture

@mradcliffe: What do you mean by testing the new markup in a browser test?

jamesdixon’s picture

Issue summary: View changes

Had a chat with @mradcliffe at DrupalCon Baltimore about what he meant when he said we needed a browser test. He means we need a BrowserTestBase web test as described here: https://www.drupal.org/node/2735005. I updated the issue summary to clarify this in the remaining tasks section.

jamesdixon’s picture

A WebTest exists for the branding block here: https://api.drupal.org/api/drupal/core%21modules%21system%21src%21Tests%...

There's a testThemeSettings() function in there which tests the theme settings which seems like a good place to test the title and alt attributes are actually showing up. Should we add our tests here to testThemeSettings()?

I believe the WebTestBase is now deprecated, and we're supposed to be using BrowserTestBase, although converting the test from WebTestBase to BrowserTestBase may be outside of the scope of this issue.

jamesdixon’s picture

Assigned: Unassigned » jamesdixon

From my discussion with the mentors it sounds like we should be adding our test to the WebTestBase that exists, and leave upgrading the test for another issue. I'm going to take a stab at updating the test to check for the title and alt attribute.

jamesdixon’s picture

Assigned: jamesdixon » Unassigned
StatusFileSize
new11.27 KB
new827 bytes

I've taken a crack at testing the alt attribute and title in the logo settings form in testThemeSettingsLogo().

I think we need to add some additional steps inside of testThemeSettings() to test the title and alt attributes actually show up in the markup as has been done for the img src.

jamesdixon’s picture

Issue summary: View changes
andrewmacpherson’s picture

Just catching up with this now. As @markconroy said, this feature request previously came up during the d7 cycle, in #717708: Document how to set logo in theme with proper alt tags. I took a look back over that issue to see why we decided not to implement it. (Thanks for tagging this @mark.)

As I recall, we got stuck on the issue of what should happen if a site builder uploaded a custom logo image, but did not specify a custom text alternative. Or vice-versa, kept the default image but customized the text alternative. The decision to won't-fix happened at the Montreal Drupal a11y sprint in 2012.

With hindsight, I think we were worrying too much about that. Nowadays, I'd rather we simply trust the site builder to use the settings responsibly. It's not as if the concept of a simple image link and text alternative are a Drupal-specific thing.

The previous issue was filed by an a11y maintainer at the time, and I was keen on it too. Now, I'm one of the a11y maintainers and I'd like to see this go ahead. Removing the "needs accessibility review tag".

Good to see that @lauriii thinks this is a non-breaking change for Stable/Classy (comment #17). If it wasn't an acceptable change for stable/classy, that would have made things much more difficult I think (because would have ended up with a feature which wouldn't work out of the box for themes which relied on Stable or Classy as a base). The use of |default() looks like a good safeguard.

I tried the patch from #40 and it seems to work well, but I haven't looked at the tests carefully.

Nice work! Really glad to see this.

andrewmacpherson’s picture

This text will be used by screen readers, search engines, or when the image cannot be loaded.

I don't like this mention of search engines in the help text. While it's certainly true that search engines like Google appear to make use of image text alternatives, they are not the intended audience. It's quite common to find images where an author has used the ALT attribute for SEO keyword stuffing, and it's very unhelpful for any of the intended scenarios. I don't want to encourage that in Drupal's UI.

jamesdixon’s picture

Issue summary: View changes

Cool, thanks for the detailed suggestions @andrewmacpherson. I'm updating the description to include what's needed at this point including your suggestion to remove search engines from the help text.

manuel garcia’s picture

StatusFileSize
new3.28 KB
new13.07 KB

Changing the help text and expanding the tests to check that the alt and title attributes are properly rendered (in bartik).

jamesdixon’s picture

Issue summary: View changes
StatusFileSize
new16.04 KB
new13.31 KB
new19.21 KB

Right on @Manuel Garcia, thanks for updating the wording and adding that test!

I applied your patch to 8.4.x and the text appears updated as shown in the attached screenshot.
https://www.drupal.org/files/issues/logo-settings-new-text.png

Also for both the default logo and a custom logo, the title and alt attributes are showing up in the markup. See screenshots attached.
https://www.drupal.org/files/issues/bartik-default.png
https://www.drupal.org/files/issues/bartik-custom-logo.png

I believe we're really close, and need a review from someone with more experience with tests. My review is a thumbs up, if the tests look good and there are no other issues found I believe this is good to go!

Updating work needed in description to reflect we need further review of tests.

mahalingam_cs’s picture

StatusFileSize
new37.21 KB
new277.95 KB
new19.24 KB
new278.57 KB

Applied patch from #45 and it worked as expected. Attached the reference screenshot. New title and the title update worked fine.

mahalingam_cs’s picture

Status: Needs review » Reviewed & tested by the community
andrewmacpherson’s picture

Status: Reviewed & tested by the community » Needs review

in #46, jamesdixon says:

I believe we're really close, and need a review from someone with more experience with tests.

We're still waiting on feedback about the tests, so setting this back to needs-review.

john cook’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs change record

I've had a look at the added tests and they all look OK.

As we've added some variables available to themers, a change record should be drafted.

There's also a "Needs issue summary update" tag. I see @jamesdixon updated it last in comment #35. Does the summary need updating further or does the tag need to be removed?.

Once they're done I think it'll be RTBC.

manuel garcia’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Thanks @John Cook!
Added the CR: https://www.drupal.org/node/2878236

andrewmacpherson’s picture

Further to what I said in #43 about the search engines. It turns out that image fields in general have the same problem, encouraging SEO abuse. I'll file a separate issue about that.

andrewmacpherson’s picture

The labels for the alt and title attributes differ to those on image field widgets.

In patch #45 here they are called "Logo alt attribute" and "Logo title attribute". On imagefield widgets they are called "Alternative text" and "Title".

Can we update these for consistency with imagefield widgets please? I think we can still keep the word "logo" in there.

andrewmacpherson’s picture

Status: Needs review » Needs work

The patch in #45 changes ImageWidget.php in Image module. That's probably out of scope for this issue, which is otherwise just about the theme settings form and branding block template.

Can we remove this, and deal with it in a separate issue?

diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
index 735cfce..e1c41da 100644
--- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
+++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
@@ -224,7 +224,7 @@ public static function process($element, FormStateInterface $form_state, $form)
       '#title' => t('Alternative text'),
       '#type' => 'textfield',
       '#default_value' => isset($item['alt']) ? $item['alt'] : '',
-      '#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
+      '#description' => t('This text will be used by screen readers, or when the image cannot be loaded.'),
       // @see https://www.drupal.org/node/465106#alt-text
       '#maxlength' => 512,
pritishkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new12.19 KB
new1.52 KB

Removed the Change in ImageWidget.php as in #54

manuel garcia’s picture

StatusFileSize
new1.83 KB
new12.17 KB

Thanks for the review, and good catch @andrewmacpherson.
Interdiff in #55 looks good, thank you @pritish.kumar

Addressing #53 on this one, and updading the CR to reflect the new theme settings field labels:
https://www.drupal.org/node/2878236/revisions/view/10483116/10483415

andrewmacpherson’s picture

I opened #2878238: Image Field Alternative text description should not encourage SEO abuse to deal with the help text on FieldAPI image fields.

manuel garcia’s picture

Status: Needs review » Reviewed & tested by the community

Tests have been given the OK, CR has been added, and the minor changes requested on #53 and #54 have been addressed. Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/config/schema/core.data_types.schema.yml
    @@ -207,6 +207,12 @@ theme_settings:
    +          type: string
    ...
    +          type: string
    

    Should be type label so they can be translated.

  2. +++ b/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php
    @@ -156,10 +156,20 @@ public function build() {
    +      '#alt' => theme_get_setting('logo.alt') ?: $this->t('Home'),
    +      '#title' => theme_get_setting('logo.title') ?: '',
    

    You don't need the ternary here - the config will always default to Home.

  3. +++ b/core/modules/system/templates/block--system-branding-block.html.twig
    @@ -11,18 +11,20 @@
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title|default('Home'|t) }}" rel="home">
    +      <img src="{{ site_logo }}" alt="{{ site_logo_alt|default('Home'|t) }}" />
    ...
    -    <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home">{{ site_name }}</a>
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title|default('Home'|t) }}" rel="home">{{ site_name }}</a>
    
    +++ b/core/themes/bartik/templates/block--system-branding-block.html.twig
    @@ -11,20 +11,22 @@
    -    <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home" class="site-branding__logo">
    -      <img src="{{ site_logo }}" alt="{{ 'Home'|t }}" />
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title|default('Home'|t) }}" rel="home" class="site-branding__logo">
    +      <img src="{{ site_logo }}" alt="{{ site_logo_alt|default('Home'|t) }}" />
    ...
    -          <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home">{{ site_name }}</a>
    +          <a href="{{ path('<front>') }}" title="{{ site_logo_title|default('Home'|t) }}" rel="home">{{ site_name }}</a>
    
    +++ b/core/themes/classy/templates/block/block--system-branding-block.html.twig
    @@ -15,13 +15,13 @@
    -    <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home" class="site-logo">
    -      <img src="{{ site_logo }}" alt="{{ 'Home'|t }}" />
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title|default('Home'|t) }}" rel="home" class="site-logo">
    +      <img src="{{ site_logo }}" alt="{{ site_logo_alt|default('Home'|t) }}" />
    ...
    -      <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home">{{ site_name }}</a>
    +      <a href="{{ path('<front>') }}" title="{{ site_logo_title|default('Home'|t) }}" rel="home">{{ site_name }}</a>
    
    +++ b/core/themes/stable/templates/block/block--system-branding-block.html.twig
    @@ -15,12 +15,12 @@
    -    <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home">
    -      <img src="{{ site_logo }}" alt="{{ 'Home'|t }}" />
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title|default('Home'|t) }}" rel="home">
    +      <img src="{{ site_logo }}" alt="{{ site_logo_alt|default('Home'|t) }}" />
    ...
    -    <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home">{{ site_name }}</a>
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title|default('Home'|t) }}" rel="home">{{ site_name }}</a>
    

    Same here we can have less logic. No need for all the default handling.

  4. +++ b/core/modules/system/config/install/system.theme.global.yml
    @@ -12,3 +12,5 @@ logo:
    +  alt: 'Home'
    +  title: 'Home'
    

    We need an update path to set this on all existing installations. And also I think we need to care about the theme settings for all installed themes too.

manuel garcia’s picture

Assigned: Unassigned » manuel garcia

Thank you @alexpott for the review, spending sometime on this today.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new6.62 KB
new12.87 KB

Addressing #59 and adding upgrade path for the global theme settings as well as all installed themes.

alexpott’s picture

Status: Needs review » Needs work

@Manuel Garcia thanks for the new patch - The update path is going to need a test.

  1. +++ b/core/modules/system/src/Form/ThemeSettingsForm.php
    @@ -212,7 +212,22 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme =
    +      $form['logo']['alt'] = [
    +        '#type' => 'textfield',
    +        '#title' => $this->t('Logo alternative text'),
    +        '#description' => $this->t('This text will be used by screen readers, or when the image cannot be loaded.'),
    +        // @see https://www.drupal.org/node/465106#alt-text
    +        '#maxlength' => 512,
    +        '#default_value' => theme_get_setting('logo.alt', $theme),
    +      ];
    +      $form['logo']['title'] = [
    +        '#type' => 'textfield',
    +        '#title' => $this->t('Logo title'),
    +        '#description' => $this->t('The title is used as a tool tip when the user hovers the mouse over the image.'),
    +        '#maxlength' => 1024,
    +        '#default_value' => theme_get_setting('logo.title', $theme),
           ];
    

    What should we do about requiring these fields - \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::process() has some complex logic for this.

  2. +++ b/core/themes/classy/templates/block/block--system-branding-block.html.twig
    @@ -15,13 +15,13 @@
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title }}" rel="home" class="site-logo">
    +      <img src="{{ site_logo }}" alt="{{ site_logo_alt }}" />
    ...
    +      <a href="{{ path('<front>') }}" title="{{ site_logo_title }}" rel="home">{{ site_name }}</a>
    
    +++ b/core/themes/stable/templates/block/block--system-branding-block.html.twig
    @@ -15,12 +15,12 @@
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title }}" rel="home">
    +      <img src="{{ site_logo }}" alt="{{ site_logo_alt }}" />
    ...
    +    <a href="{{ path('<front>') }}" title="{{ site_logo_title }}" rel="home">{{ site_name }}</a>
    

    New variables to document.

manuel garcia’s picture

Assigned: manuel garcia » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.36 KB
new15.46 KB
  • Added test for the upgrade path (my first!)
  • Re #62.2 - Added documentation for the new variables to classy and stable (which was also missing it). Thanks @alexpott for your good eyes... I've also checked the other two templates, they all have these now.

As for #62.1, ImageWidget uses '#alt_field_required' for this, though I'm not sure I follow what you mean here, this is not a field, just plain old form? Should just make the logo alt and title required?

Also, I've been scratching my head for a while, but I don't see why we've got failing tests from UpdatePathTestBase::runUpdates(), it is complaining that stable.settings and classy.settings have no schema. However the configuration does save properly... can anyone help with this one?

Status: Needs review » Needs work

The last submitted patch, 63: 2780293-63.patch, failed testing.

john cook’s picture

@Manuel, I found this dealing with schemea problem: https://www.drupal.org/node/2654810. Maybe it will be of help here.

manuel garcia’s picture

Thanks @John Cook, I've spent a good hour trying to figure this out, but no luck.

Here's what I've found, in hope that someone else can continue this:

  • Since the settings form for bartik and seven have never been saved, they've got no configuration.
  • UpdatePathTestBase::runUpdates() seems to treat that situation as a fail for some reason (Saving them when they didn't exist before).
  • However, shortcut_install() does the exact same thing for seven theme.
  • I've been trying to see how ThemeSettingsForm does it, but I see nothing different so far.
  • The update hook itself works, as my test added on #63 proves. I've also tested the code manually on a local installation.

I'm guessing we should be checking if we've got configuration for each theme, if so then load it, set the new values, and save it. Otherwise, create a new one "properly", set the new values and save it.

\Drupal::configFactory()->getEditable('bartik.settings')->set('logo.alt', 'Home')->save(TRUE); doesn't seem to be the way to go about it, although you can definitely do this in custom code. Any pointers would be very welcome :)

alexpott’s picture

+++ b/core/modules/system/system.install
@@ -1927,3 +1927,23 @@ function system_update_8400(&$sandbox) {
+  foreach ($theme_handler->listInfo() as $theme) {
+    \Drupal::configFactory()->getEditable($theme->getName() . '.settings')
+      ->set('logo.alt', 'Home')
+      ->set('logo.title', 'Home')
+      ->save(TRUE);
+  }

You only should be writing is the theme settings have been customised.

  foreach ($theme_handler->listInfo() as $theme) {
    $theme_settings = \Drupal::configFactory()->getEditable($theme->getName() . '.settings');
    // Only update if a theme settings exists.
    if (!$theme_settings->isNew()) {
      $theme_settings
        ->set('logo.alt', 'Home')
        ->set('logo.title', 'Home')
        ->save(TRUE);
    }
  }

As base themes classy and stable are not customisable. This means you need to ensure that bartik.settings actually exists in the update path test.

andrewmacpherson’s picture

Re: #62.1 - the logo image absolutely MUST have alt text, because it is the only content inside a link. Without it, we would have a link without a text value:

<a href="/" title="" rel="home" class="site-branding__logo">
  <img src="/core/themes/bartik/logo.svg" alt="">
</a>

That's a WCAG 2 failure at level A , specifically F89: Failure of Success Criteria 2.4.4, 2.4.9 and 4.1.2 due to not providing an accessible name for an image which is the only content in a link.

I thought this was why we had the Twig default values like this: alt="{{ site_logo_alt|default('Home'|t) }}". They were flagged in #59.3 and removed in patch #61.

We could just make the alt field mandatory in the them settings form, but I'm a bit worried that there isn't an easy way for a user to set it back to the default. With the Twig default, leaving it blank would still result in ALT text, and the description could say it defaults to "Home" if left blank. (Caveat: can this default vary per theme?)

The logo title attribute doesn't have to be mandatory.

alexpott’s picture

@andrewmacpherson it's not the twig template's job to make it easy to revert to default. Making it required in the form is best because then when the user tries to set it to empty they get an error rather than the alt text being unexpectedly set to Home for reasons that are not obvious.

john cook’s picture

Status: Needs work » Needs review
StatusFileSize
new15.58 KB
new1.44 KB

I've changed the update function as suggested by alexpotts in #67. It works when testing locally, we'll se what testbot makes of it.

I've also made the alt text field mandatory from the comments by andrewmacpherson (#68) and alex (#69.

Status: Needs review » Needs work

The last submitted patch, 70: 2780293-70.patch, failed testing.

john cook’s picture

StatusFileSize
new15.64 KB
new1.24 KB

Added the same code for the update function (from #67) to the test to ensure that only active themes have their settings checked.

john cook’s picture

Status: Needs work » Needs review
alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/src/Tests/Update/SiteLogoAltTitleAddedTest.php
@@ -0,0 +1,61 @@
+    // Check that each enabled theme has the expected values after the update.
+    foreach ($this->themeHandler->listInfo() as $theme) {
+      $theme_settings = $this->config($theme->getName() . '.settings');
+      if (!$theme_settings->isNew()) {
+        $this->assertEqual($theme_settings->get('logo.alt'), 'Home');
+        $this->assertEqual($theme_settings->get('logo.title'), 'Home');
+      }
+    }

Rather than a foreach here it would be great to be more explicit as this is a test.

john cook’s picture

StatusFileSize
new15.54 KB
new1.21 KB

I've changed the test so that in only checks the setting for the seven theme, as suggested by alexpott in #74.

john cook’s picture

Status: Needs work » Needs review
dinesh18’s picture

StatusFileSize
new100.13 KB
new31.53 KB

I have tested the patch mentioned in comment #75 and it is working as expected.
PFA screengrab before and after patch.

manuel garcia’s picture

StatusFileSize
new62.64 KB

Ah beautiful thank you @John Cook for the work, and @alexpott for the explanations, makes perfect sense now.

To answer #68 very valid concern on accessibility, there is no need to handle defaults on the twig files like alex said, drupal already handles this for us. Double checked just in case, on a brand new drupal installation with this patch, markup looks like this:

<!-- BEGIN OUTPUT from 'core/themes/bartik/templates/block--system-branding-block.html.twig' -->
<div id="block-bartik-branding" class="contextual-region clearfix site-branding block block-system block-system-branding-block">
  
    <div data-contextual-id="block:block=bartik_branding:langcode=en"></div>
        <a href="/" title="Home" rel="home" class="site-branding__logo">
      <img src="/core/themes/bartik/logo.svg" alt="Home" />
    </a>
        <div class="site-branding__text">
              <div class="site-branding__name">
          <a href="/" title="Home" rel="home">drupal8</a>
        </div>
                </div>
  </div>

<!-- END OUTPUT from 'core/themes/bartik/templates/block--system-branding-block.html.twig' -->

Changes to the tests look fine, to me, tempted to RTBC, just one thing:

+++ b/core/modules/system/src/Tests/Update/SiteLogoAltTitleAddedTest.php
@@ -48,11 +48,11 @@ public function testSiteLogoAltTitleAdded() {
-    // Check that each enabled theme has the exepected valuesafter the update.
-    foreach ($this->themeHandler->listInfo() as $theme) {
-      $this->assertEqual($this->config($theme->getName() . '.settings')->get('logo.alt'), 'Home');
-      $this->assertEqual($this->config($theme->getName() . '.settings')->get('logo.title'), 'Home');
-    }
+    // Check the settings for the seven theme to make sure that they are the
+    // expected values after the update.
+    $theme_settings = $this->config('seven.settings');
+    $this->assertEqual($theme_settings->get('logo.alt'), 'Home');
+    $this->assertEqual($theme_settings->get('logo.title'), 'Home');

Should we be testing for other core themes as well or does checking seven suffice?

john cook’s picture

@Manuel, I checked when it looped which themes passed and seven was the only one that did.

I think that seven is the active theme when doing the test, with no other themes enabled.

manuel garcia’s picture

Status: Needs review » Reviewed & tested by the community

@John Cook ah, perfect then, thanks for clarifying.

manuel garcia’s picture

Title: No GUI way to add logo img alt and title attributes » Add GUI to configure the site's logo alt and title attributes
lauriii’s picture

Status: Reviewed & tested by the community » Needs work

The current upgrade path is missing support for translations. This is a BC break which we don't want to introduce. I suggest that we iterate through all the languages site has enabled, and create configuration translation in each language. We should also extend the test coverage for this use case.

penyaskito’s picture

@Manuel Garcia asked for help on IRC, so I jumped in and took a look as how this should look like.

+++ b/core/modules/system/system.install
@@ -1927,3 +1927,26 @@ function system_update_8400(&$sandbox) {
+/**
+ * Set the default Logo alt and title.
+ */
+function system_update_8302() {
+  // Set the values for the global theme settings.
+  \Drupal::configFactory()->getEditable('system.theme.global')
+    ->set('logo.alt', 'Home')
+    ->set('logo.title', 'Home')
+    ->save(TRUE);
+
+  // Set the values for all currently installed themes.
+  $theme_handler = \Drupal::service('theme_handler');
+  foreach ($theme_handler->listInfo() as $theme) {
+    $theme_settings = \Drupal::configFactory()->getEditable($theme->getName() . '.settings');
+    if (!$theme_settings->isNew()) {
+      $theme_settings
+        ->set('logo.alt', 'Home')
...
+        ->save(TRUE);
+    }
+  }
+}

We would need there something along:

  /** ConfigurableLanguageManager $manager */
    if ($manager->isMultilingual()) {
      $languages = $manager->getLanguages();
      foreach ($languages as $langcode => $language) {
        $configOverrideStorage = $manager->getLanguageConfigOverrideStorage($langcode);
        if ($configOverrideStorage->exists('system.theme.global')) {
          $configOverride = $manager->getLanguageConfigOverride($langcode, 'system.theme.global');
          // Hey, how are you getting proper translations?
          $configOverride->set('logo.alt', t('Home', [], ['langcode' => $langcode]))
            ->set('logo.title', t('Home', [], ['langcode' => $langcode]))
            ->save();
        }
      }
    }

Here I assumed that we only want to write the configuration translation if it was already translated to that language.

Open questions: how do we get default values? t('Home', [], ['langcode' => $langcode]) is one option, but in most cases there won't be a translation already in the site.

manuel garcia’s picture

StatusFileSize
new1.54 KB
new16.48 KB

Thanks @laurii for the review and thanks @penyaskito for kindly explaining this.

Attached the updated upgrade path, which creates a new configuration translation for each language (or updates it if it was there already).

Tested this manually with a fresh install of Drupal in English and Spanish, then ran the update - seems to work as expected... I'd love a quick review before extending the test coverage though :)

manuel garcia’s picture

Status: Needs work » Needs review
penyaskito’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/system.install
@@ -1949,4 +1949,24 @@ function system_update_8302() {
+      else {
+        $configOverrideStorage->write('system.theme.global', ['logo' => ['alt' => $value_to_save, 'title' => $value_to_save]]);
+      }

Not sure if you want to create the override if it didn't existed before.

+++ b/core/modules/system/system.install
@@ -1927,3 +1927,46 @@ function system_update_8400(&$sandbox) {
+    $theme_settings = \Drupal::configFactory()->getEditable($theme->getName() . '.settings');

You also want to edit these config translations in the same way

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new2.29 KB
new16.89 KB

Thanks again @penyaskito for the review & explanations, here some progress hopefully addressing #86 :)

One thing that still worries me about all this is that I don't see these to be translated on /admin/config/regional/config-translation - is this expected or? How would one go about translating these two then?

manuel garcia’s picture

StatusFileSize
new16.86 KB

Rerolling, a new update hook was added to system.install.

manuel garcia’s picture

StatusFileSize
new2.98 KB
new18.7 KB

Here is my attempt at adding test coverage for the multilingual part of the upgrade path, however it is failing for me.

I'm not sure whether the test is wrong or whether the changes made since #75 need to be looked at (or both).

In any case this is as far as I can go - any help would be very welcome =]

Status: Needs review » Needs work

The last submitted patch, 89: 2780293-89.patch, failed testing. View results

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andrewmacpherson’s picture

The Umami demo profile has a real need for this. (I know, that seems the wrong way around. Umami is supposed to be a demo of Drupal's existing features, rather than driving requests for new features...)

Currently the Umami branding block uses a logo image which shows the site name in a fancy font, AND it adds .visually-hidden to the site name display. The upshot of this is that the Umami branding block shows the site name to sighted users, and has a visually-hidden site name for screen readers.

But there's a huge accessibility problem with this. The visually hidden site name is a link, so there's an operable link in there which cannot be perceived + understood by sighted keyboard users. It's a WCAG failure of "Focus Visible".

A better approach for Umami would be to uncheck the site name display option, and set the logo alt text to "Umami Food Magazine", which is exactly what THIS issue would provide.

I think the situation with the Umami header design reflects a common scenario, so it justifies this feature.

manuel garcia’s picture

Assigned: Unassigned » manuel garcia
Issue tags: +Needs reroll

Nearly forgot about this one, re-rolling for now...

manuel garcia’s picture

Assigned: manuel garcia » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new18.57 KB
new5.99 KB

Status: Needs review » Needs work

The last submitted patch, 96: 2780293-96.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new5.4 KB
new18.79 KB

Cleaning up the old test to be in line with current times.

Status: Needs review » Needs work

The last submitted patch, 98: 2780293-98.patch, failed testing. View results

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new4.28 KB
new19.13 KB

Some more cleanup and hopefully fixing one of the failing tests.

Status: Needs review » Needs work

The last submitted patch, 100: 2780293-100.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new2.84 KB
new18.96 KB

A bit more cleanup and getting the new SiteLogoAltTitleAddedTest to pass up to where we check for the language config override of seven.settings.

Not sure why it fails there, I've debugged the update function and it seems to run correctly.

Perhaps its because of why we're setting up the test here?

Any pointers would be welcome at this stage, not very familiar with this part of core, so I'm blocked for now...

Status: Needs review » Needs work

The last submitted patch, 102: 2780293-102.patch, failed testing. View results

manuel garcia’s picture

I cant reproduce this failure shown by the bot when I run the test locally:
Schema key block.block.bartik_account_menu:settings.cache failed with: missing schema

andrewmacpherson’s picture

Good to see this moving, thanks @Manuel.

I tried out the UI, and it's looking good. We recently updated the FAPI #descriptions for the alt text in Editor and Image modules, in #2991149: Improve placeholder text for image upload. There, we got rid of bad advice which said the alt text was for search engines, so I wanted to check what the logo alt #description said here. I'm happy with it. Looking back over this issue history, it seems I first had the idea to remove the bad SEO advice in comment #43 here.

I skim-read the update hook here. I haven't tested it, but going by the code comments it looks like it's all in hand, and there's a test for the update.

I'll let someone else review the update path and tests in detail. The GUI and output are ready.

mradcliffe’s picture

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

I added the DrupalEurope issue tag and we can work on this. Update tests can be difficult to debug, but this could be a missing module in the test that needs to be included in this test in addition to the base class.

Status: Needs review » Needs work

The last submitted patch, 102: 2780293-102.patch, failed testing. View results

bserem’s picture

I am also getting different results:

1) Drupal\Tests\system\Functional\Update\SiteLogoAltTitleAddedTest::testSiteLogoAltTitleAdded                       
Failed asserting that null matches expected 'Home'

Don't know if this helps anyone.

manuel garcia’s picture

Yeah that is what I see locally too @bserem - though I don't know why it happens, my guess is we're setting up the test incorrectly, but I don't know how to set it up otherwise...

mradcliffe’s picture

@tashaharrison80, @sysosmaster, and I are working on this together at DrupalEurope.

The update is running fine in the test, but we believe that the themes are not installed correctly (particularly seven).

mradcliffe’s picture

We found that the test failure noted by @bserem is correct. We've (@sysosmaster) concluded the test should pass if the translation is working as it is supposed to be.

We (@tasharobinson80) tested manually and found that the alt/title are not translated while using a different language and a non-default theme. However it is being translated when a theme is the global theme.

We confirmed the update is running successfully as well on multiple environments and themes (seven, bartik, stark).

This might be a bug in the language configuration overrides or the theme settings in this patch.

I think the next step is to look at the rest of the patch and see how the configuration is coming in.

mradcliffe’s picture

Actually, @tasharobinson80 pointed out that the last part of the update isn't running at all so the config override doesn't exist for the theme settings and thus isn't getting set.

It's also hard to look at the issue because we're not sure the user interface for language config overrides quite yet. Probably need to look up the documentation around that.

sysosmaster’s picture

worked on this with @tashaharrison80 and @mradcliffe. @ Drupaleurope

andypost’s picture

Since 8.6 logo can be svg or image https://www.drupal.org/node/2939152

It means that theme should be smart enough to display "alt" depending on type of logo
- alt for images
- aria-label for svg for accessibility

+++ b/core/modules/system/config/install/system.theme.global.yml
@@ -12,3 +12,5 @@ logo:
+  alt: 'Home'

Why alt default value is "Home" instead of "Logo" which is should explain what this element is about

andrewmacpherson’s picture

@andypost - no, the suggestions in #144 are going off-track.

That change record is about specifying a default logo path & filename in info files. It didn't change the types of image which could be used as a logo, just removed a hard-coded default filename. We've always been able to use SVG, JPEG, PNG, as a custom logo in D8.

It doesn't matter whether the logo is SVG or a raster format, the file is used as the <img src>. So there's no need to use aria-label - the first rule of using ARIA is that you don't use ARIA when a HTML mechanism is available. When an <img src> points to an SVG, the alt attribute is the correct way to provide a text alternative.

Aside: on the other hand, if the <svg> document was embedded in the HTML directly, then aria-label would be appropriate. That's not the case with the branding block though.

Why alt default value is "Home" instead of "Logo" which is should explain what this element is about

Remember the logo image is also a link, so we must convey the purpose of the link. That's more important than describing the image itself. "Logo" helps nobody because it's too vague - it describes neither the image itself, nor the purpose of the link.

"Home" describes the purpose of the link, and is currently hard-coded in the branding block template. It's a reasonable default, and this patch allows profiles to override it with installation config.

Some examples may explain this better.

  1. In Standard profile, Bartik's branding block shows the the default druplicon logo, followed by the site name. Both are links to the home page. The logo image contains no text, and mainly serves as decoration. However it's an operable link, and we must convey the purpose. We won't use the site name here, because that's present in nearby text. So alt="home" will suffice. The same applies for the Minimal profile with the Stark theme, and many contrib distros.
  2. In the Umami demo profile, the default logo is an image of text. In this case the logo's text alternative should match the the text it contains, i.e. alt="Umami Food Magazine" (or perhaps alt="Umami Food Magazine - Home"). This is an image used alone as a linked logo. See also example 9 in Understanding WCAG SC 1.1.1 Non-text Content. Since the logo image has the site name, we don't want to display the site name text link at all. Currently it is visually-hidden, but this causes problems for sighted keyboard users, so we'll be turning it off in the branding block config once this patch is in. This scenario applies to many web sites, and perhaps some distros too.

andrewmacpherson’s picture

Adding sprint credits from #112-113

manuel garcia’s picture

Status: Needs work » Needs review
Issue tags: -Accessibility +accessibility
StatusFileSize
new19.09 KB

Rerroll of #102, simple conflict on system.install.

manuel garcia’s picture

StatusFileSize
new1.22 KB
new19.1 KB

Just a small cleanup to use public static $modules = ['language']; to enable the language module in the test.

I think the last failures on the test might've been because of random test bot failures, Schema key block.block.bartik_account_menu:settings.cache failed with: missing schema doesnt seem to be related to this patch.

The last submitted patch, 118: 2780293-118.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 119: 2780293-119.patch, failed testing. View results

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new1.84 KB
new19.57 KB

This should get the test to actually run.

I noticed that the previous failure is still happening:

There was 1 failure:

1) Drupal\Tests\system\Functional\Update\SiteLogoAltTitleAddedTest::testSiteLogoAltTitleAdded
Failed asserting that null matches expected 'Home'.

/var/www/drupal8/core/tests/Drupal/Tests/BrowserTestBase.php:699
/var/www/drupal8/core/modules/system/tests/src/Functional/Update/SiteLogoAltTitleAddedTest.php:100

So I added assertions to check that the language config overrides exist, and apparently for seven.settings it doesnt:

There was 1 failure:

1) Drupal\Tests\system\Functional\Update\SiteLogoAltTitleAddedTest::testSiteLogoAltTitleAdded
Configuration override for seven.settings in Spanish exists
Failed asserting that false is true.

/var/www/drupal8/core/tests/Drupal/KernelTests/AssertLegacyTrait.php:35
/var/www/drupal8/core/modules/system/tests/src/Functional/Update/SiteLogoAltTitleAddedTest.php:103

I've tried reseting the language manager and rebuilding the container after creating the language, but no luck.

If anyone knows why this is happening I'd be very keen to hear it :)

Status: Needs review » Needs work

The last submitted patch, 122: 2780293-122.patch, failed testing. View results

manuel garcia’s picture

OK did a bit more digging, it seems that actually these theme settings are not currently translatable as far as I can see...

I tried adding this to the system.config_translation.yml file but getting access denied when accessing /admin/appearance/settings/translate:

system.theme_settings:
  route_name: system.theme_settings
  title: 'Appearance settings'
  base_route_name: system.theme_settings
  names:
    - theme_settings.alt
    - theme_settings.title

So still blocked, but the update test seems to have picked up an actual bug in the current patch so that’s good news.

manuel garcia’s picture

Seems to me like we'd need #2154743: Support route parameters for *.config_translation.yml files' base_route_name properties for this to happen?
I don't think core theme settings are actually translatable at the moment? I believe this is blocked unless someone figures out a way forward.

vijaycs85’s picture

Its also worth noting that the [theme_name].settings config is not really getting installed as part of theme install. Only config we can see when installed with standard profile is seven.settings and looks like it exists only because of the 3rd party settings from shortcut module.

//seven.settings.yml
a:2:{s:20:"third_party_settings";a:1:{s:8:"shortcut";a:1:{s:11:"module_link";b:1;}}s:4:"logo";a:2:{s:3:"alt";s:4:"Home";s:5:"title";s:4:"Home";}}
tim.plunkett’s picture

Issue tags: -Drupalaton, -accessibility (duplicate tag), -Dublin2016, -dcffm17, -Baltimore2017, -DrupalEurope +Accessibility

Fixing tags

andrewmacpherson’s picture

Issue tags: +accessibility (duplicate tag)

The accessibility tag has been behaving strangely over the last month. I'll ask the drupal.org webmasters for help, but for the meantime leave both tags in place.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

Issue tags: -accessibility (duplicate tag)

Fixing tagging.

justinbmc’s picture

I am working on this issue at DrupalCon 2019 Seattle, though a newbie and may not be helping much! No longer looking at this. Sorry!

sonu.raj.chauhan’s picture

StatusFileSize
new19.27 KB
sonu.raj.chauhan’s picture

StatusFileSize
new19.3 KB
sonu.raj.chauhan’s picture

sonu.raj.chauhan’s picture

StatusFileSize
new19.24 KB
sonu.raj.chauhan’s picture

StatusFileSize
new19.31 KB
sonu.raj.chauhan’s picture

vacho’s picture

@sonu.raj.chauhan Hi, thanks for collaborating. Please always set a comment describing your work over this case and too a interdiff file that describe the changes on git.

BTW patchs 123, 124, 135 and 136 (by @sonu.raj.chauhan) are the same code.

vacho’s picture

StatusFileSize
new2.67 KB
vacho’s picture

Issue tags: +Needs reroll
vacho’s picture

Issue tags: -Needs reroll
StatusFileSize
new19.52 KB
new2.62 KB

Patch 122 rerolled and some update to twigs files and system.install

shaal’s picture

Status: Needs work » Needs review
StatusFileSize
new21.41 KB
new1.75 KB

I updated Umami's theme to use the new settings for the logo.

I added a missing empty line at the end of system.install file.

Status: Needs review » Needs work

The last submitted patch, 142: core-theme-add-logo-gui-2780293-142.patch, failed testing. View results

volkswagenchick’s picture

Issue tags: +dcco2019

Tagging for DrupalCamp Colorado 2019 (Sunday August 4)

aleevas’s picture

Status: Needs work » Needs review
StatusFileSize
new21.59 KB
new726 bytes

Here is my patch

aleevas’s picture

StatusFileSize
new18.62 KB
new726 bytes

Oops, sorry, was a wrong patch.
This one should be better.

manuel garcia’s picture

So glad to see other people pushing this forward, I totally hit a brick wall on this and had lost hope :)

Re #146:

@@ -149,7 +265,7 @@
-+        if ($configOverrideStorage->exists($theme_settings_name)) {
++        if (!$configOverrideStorage->exists($theme_settings_name)) {

I'm not entirely sure this is what we want to do... shouldn't we be updating only if the language configuration override exists already?

andrewmacpherson’s picture

The site logo no longer uses a title attribute since #2920395: SystemBrandingBlock has identical anchor title and link content (image alt).

A GUI to set the logo alternative text is still desirable, but there's no longer a need for a GUI to set the logo title attribute. The parts dealing with the logo title attribute can be removed from this patch. I'll work on that today.

andrewmacpherson’s picture

Title: Add GUI to configure the site's logo alt and title attributes » Add GUI to configure the site's logo alt attribute
andypost’s picture

Status: Needs review » Needs work

Setting to NW because template translation should not be used

Also I think it could be slightly simplified by extending the block setting... I see no reason to introduce a theme setting additionally

+++ b/core/includes/theme.inc
@@ -480,6 +480,12 @@ function theme_settings_convert_to_config(array $theme_settings, Config $config)
+      $config->set('logo.alt', $value);
...
+      $config->set('logo.title', $value);

+++ b/core/modules/system/config/install/system.theme.global.yml
@@ -12,3 +12,5 @@ logo:
+  alt: 'Home'
+  title: 'Home'

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -239,6 +239,22 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme =
+        '#default_value' => theme_get_setting('logo.alt', $theme),
...
+        '#default_value' => theme_get_setting('logo.title', $theme),

+++ b/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php
@@ -159,10 +159,20 @@ public function build() {
-      '#alt' => $this->t('Home'),
+      '#alt' => theme_get_setting('logo.alt'),
+      '#title' => theme_get_setting('logo.title'),
...
+    $build['site_logo_alt'] = [
+      '#markup' => theme_get_setting('logo.alt'),

+++ b/core/modules/system/templates/block--system-branding-block.html.twig
@@ -11,18 +11,20 @@
-      <img src="{{ site_logo }}" alt="{{ 'Home'|t }}" />
+    <a href="{{ path('<front>') }}" title="{{ site_logo_title|t }}" rel="home">
+      <img src="{{ site_logo }}" alt="{{ site_logo_alt|t }}" />
...
-    <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home">{{ site_name }}</a>
+    <a href="{{ path('<front>') }}" title="{{ site_logo_title|t }}" rel="home">{{ site_name }}</a>

Both title and alt stored in config and should use config translation instead of template level translation (it's easy to miss quotes in template)

On other hand block config form could be improved to allow configure alt and title per block instance (it will also use config translation for block) - then theme setting could be used as default... but block already has own defaults

andrewmacpherson’s picture

Status: Needs work » Needs review
StatusFileSize
new17.6 KB
new1.14 KB

A regression crept in with patch #145:

diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index 258930e..cabbe2e 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -2,6 +2,7 @@

 namespace Drupal\system\Form;

+use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Config\PreExistingConfigException;
 use Drupal\Core\Config\UnmetDependenciesException;
 use Drupal\Core\Access\AccessManagerInterface;
@@ -323,7 +324,7 @@ protected function buildRow(array $modules, Extension $module, $distribution) {
     /** @var \Drupal\Core\Extension\Dependency $dependency_object */
     foreach ($module->requires as $dependency => $dependency_object) {
       if (!isset($modules[$dependency])) {
-        $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">missing</span>)', ['@module' => $dependency]);
+        $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">missing</span>)', ['@module' => Unicode::ucfirst($dependency)]);
         $row['enable']['#disabled'] = TRUE;
       }
       // Only display visible modules.

This doesn't appear in the interdiff in #145 so I went looking via git blame. It looks like this is an unintentional reversion of #3042999: Remove ucfirst() from missing dependencies on the Extend page.

This patch fixes that.

andrewmacpherson’s picture

Assigned: Unassigned » andrewmacpherson

I'm working on #148 just now.

#150:

I think I see what you mean about template translation. I try that after addressing #148.

Also I think it could be slightly simplified by extending the block setting... I see no reason to introduce a theme setting additionally

But the logo image is specified at the theme settings page. The alt text should be set in the same form.

andrewmacpherson’s picture

StatusFileSize
new13.1 KB
new15.02 KB

This patch addresses #148, by removing everything to do with the custom title attribute. Now the patch just provides a GUI for the logo's text alternative.

It doesn't address #150 yet.

Also, I noticed that the template files were updating the title attribute on the site-name link too:

   {% if site_name %}
-    <a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home">{{ site_name }}</a>
+    <a href="{{ path('<front>') }}" title="{{ site_logo_title|t }}" rel="home">{{ site_name }}</a>
   {% endif %}

That's out of scope for this issue, which is just about the logo image, not the site-name. I've undone this change in each template.

andrewmacpherson’s picture

Assigned: andrewmacpherson » Unassigned
StatusFileSize
new3.31 KB
new13.09 KB

Addresses the template translation part of #150.

I don't really grok the config translation issue that Manuel Garcia linked in #125... #2154743: Support route parameters for *.config_translation.yml files' base_route_name properties

andrewmacpherson’s picture

Issue tags: -Novice

Probably not a novice issue any more.

manuel garcia’s picture

Status: Needs review » Needs work

Thanks a bunch for working on this.

Looks like we dropped the update path test SiteLogoAltTitleAddedTest from the patch since #146, setting to needs work because of that. It'll probably also need updating as well since we are removing everything to do with the custom title attribute.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new3.91 KB
new16.9 KB

Adding back the update path test, removing the parts that were testing the logo.title configuration since we're no longer adding it.

guptahemant’s picture

StatusFileSize
new17.44 KB
new2.62 KB

Hi everyone
We have been using patch from #122 and than an updated patch from #135 for a long time, now since then this issue has been updated a lot and now the correct update hook is 8703, Now if we apply the latest patch on our sites it will result in data loss, To avoid this i am attaching an updated patch which reads the existing alt text values from db first and than apply the values.

Please review.
Thanks

manuel garcia’s picture

Re #151:
Thanks for reporting about running the patch for a long time, looks like its working correctly I assume :)

I'm not sure core should account for such situations where the update hook updates the value of your patched config. That said, I dont think it hurts to check it just in case. In my opinion tough if the configuration has an existing value, we should not save it again with the same value.

A quick eyeball review of the interdiff on #151:

+++ b/core/modules/system/system.install
@@ -2379,9 +2380,8 @@ function system_update_8703() {
@@ -2397,17 +2397,17 @@ function system_update_8703() {

@@ -2397,17 +2397,17 @@ function system_update_8703() {
       $value_to_save = t('Home', [], ['langcode' => $langcode]);
       // Update the override for global theme settings.
       if ($configOverrideStorage->exists('system.theme.global')) {
-        $language_manager->getLanguageConfigOverride($langcode, 'system.theme.global')
-          ->set('logo.alt', $value_to_save)
-          ->save();
+        $global_config_translated = $language_manager->getLanguageConfigOverride($langcode, 'system.theme.global');
+        $alt_value = $global_config_translated->get('logo.alt') ?: $value_to_save;
+        $global_config_translated->set('logo.alt', $value_to_save)->save();
       }
       // Update the override for each installed theme settings.
       foreach ($installed_themes as $theme) {
         $theme_settings_name = $theme->getName() . '.settings';
         if (!$configOverrideStorage->exists($theme_settings_name)) {
-          $language_manager->getLanguageConfigOverride($langcode, $theme_settings_name)
-            ->set('logo.alt', $value_to_save)
-            ->save();
+          $theme_settings_translated = $language_manager->getLanguageConfigOverride($langcode, $theme_settings_name);
+          $alt_value = $theme_settings_translated->get('logo.alt') ?: $value_to_save;
+          $theme_settings_translated->set('logo.alt', $value_to_save)->save();
         }
       }
     }

These are still saving the new configuration value even if there was an existing one.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bharti mehta’s picture

StatusFileSize
new17.44 KB

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new147 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mgifford’s picture

Issue tags: +wcag111

Looks like WCAG SC 1.1.1 may still be a problem. I have not tested if this is the case with the latest patch.

bharath-kondeti made their first commit to this issue’s fork.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.