Problem/Motivation

For accessibility reasons, it is likely to have a different page title for different pages. Paginated Views provides an unique title for all the pages of the same View.

Proposed resolution

Allow to use the title area handler everywhere (see attached patch from @dawehner)
Overwrite the title of the views provided by the Core to append the page number to their title.

Remaining tasks

Discuss, patch, review, commit.

User interface changes

Views UI is going to allow to use its title handler everywhere.

API changes

None.

Data model changes

Some new settings in the View config entity.

Issue fork drupal-2509716

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DuaelFr’s picture

Issue summary: View changes
DuaelFr’s picture

Issue tags: +Accessibility, +VDC
dawehner’s picture

To be clear, if we allow the title area handle to be used everywhere, all this is already possible.

On the other hand I think maybe for the frontpage view we could set it by default, on the other hand I don't think we should assume anything the way how people build
their site, so the default for new views should not be filled with all kind of stuff.

DuaelFr’s picture

Updated IS after a discussion on IRC.

mgifford’s picture

Status: Active » Needs review

That's it? Will have to find time to test it out. What is the best way to test this?

DuaelFr’s picture

Status: Needs review » Needs work
Issue tags: -a11y, -SEO

Nope, that's just a patch provided by @dawehner to allow to use the title handler everywhere.
We still have to alter the default views and to write some tests.

mgifford’s picture

Issue tags: +Needs tests

Ok. Think this is something we can do within 8.0?

dawehner’s picture

Well yes, default views could provide that, but at the same time, I don't think it would be a good idea to enforce it.

DuaelFr’s picture

It depends on the focus we want to have on accessibility.
The page title is always the first thing a screen/Braille reader reads so if that title does not change, the user have no clue about the fact that the content changed or not. If that user comes from an external link, the page number in the page title could be an interesting clue on how fresh the content he is watching is.

For aesthetic reasons, the first page should not have it title rewrited. That's why I wanted to use something more specific than the existing title rewriter that works with tokens. Plus, it should be more understandable for site builder to have a dedicated handler with a relevant name.

dawehner’s picture

Well, you could make an advanced option on the title area handler, which also allows you to set the title different for the first page, for example.

mgifford’s picture

@dawehner - I don't see how appending the page number is anything but a best practice for everyone. Why wouldn't it be a good idea to know where you are midway in a view of 1000 pages?

It isn't how Google does it, but really can't see much argument opposed to it other than that.... Mind you Google has very mixed results on accessibility and don't think is striving for WCAG 2.0 AA.

I'm fine with adjusting the patch to see that this can be disabled through the UI and that the first page or initial text (can be customized). I think that the default should be to include the page number in the title though.

The closest I could find for pagination for this in WCAG is:
http://www.w3.org/TR/UNDERSTANDING-WCAG20/navigation-mechanisms-title.html

But this is a requirement for WCAG 2.0 A which is below our requirements. This might well be a bug rather than a feature. @DuaelFr thoughts on this?

DuaelFr’s picture

Issue tags: +Needs beta evaluation

Thank you Mike for looking into the WCAG specs to find the closest reference and to keep that issue alive ;)

I don't know if we can categorize this as a bug. For me, a bug is when the software does not fulfill the functional promise. In this case, everything works the way it is expected to.

If the WCAG 2.0 is something Drupal wants to follow (and it should) and if this issue is a clear blocker, I suppose we could make it pass the beta evaluation, even without turning that issue into a bug report.

We might need a core maintainer opinion right now to avoid spending a lot of time on something that could be postponed unless @dawehner or another Views maintainer wants to judge.

mgifford’s picture

Category: Feature request » Bug report
FileSize
40.42 KB

The goal of Drupal 8 is to be WCAG 2.0 AA. If it isn't, it can be considered a bug. How important we prioritize that is another issue. Just because it's an accessibility bug doesn't mean that it is a blocker though.

I am a core maintainer, but certainly appreciate input from folks like @dawehner who know this module so much more.

Having a tolken like @DuaelFr described in #9 would be ideal. I've just thrown this together quickly with what I think we are looking for:

Screenshot of view form.

The pagination should be in the title by default but easily removed.

mikeker’s picture

Assigned: Unassigned » mikeker

Investigating the idea of a [page_number] token for use in area handlers.

mikeker’s picture

Turns out we already have [view:current-page] and [view:page-count] tokens, though the page-count token is incorrect: #2572355: Some view tokens ([view:page-count] and [view:total-rows]) are incorrect.

Now looking into what it takes to get those tokens to render for the title field.

mikeker’s picture

Attached patch allows global tokens in the display title.

mikeker’s picture

Self review:

  1. +++ b/core/modules/views/src/ViewExecutable.php
    @@ -1710,6 +1710,9 @@ public function getTitle() {
    +    $title = $this->display_handler->globalTokenReplace($title);
    

    We're not passing a langcode in the $options argument to globalTokenReplace(). Is that bad? Or is that only to override the default langcode?

    Would love to hear from i18n folks on this.

  2. +++ b/core/modules/views/views.views.inc
    @@ -75,7 +75,6 @@ function views_views_data() {
    -      'sub_type' => 'empty',
    

    Can someone explain this to me? It came up in #4 so I left it in... But if it just allows the title handler to be used in other "area" spots (header, footer, etc.) that won't help us in this case because the view title is (somewhat oddly) rendered in the ViewExecutable object rather than the display handler and isn't an "area".

mgifford’s picture

I can't answer #17.1 or #17.2, but did test out the patch in #16 and it didn't change the defaults or the help text associated with the title element.

I could add in the existing page here:

Unfortunately I don't think we want the output to the page to be the same as the title of the page. So the results here:

You don't actually want to change the text out of the header. It would also be nice if the "Page #" were just a translated string that was available as a token rather than the raw page number.

And it doesn't treat the first page as special if you want to define it as " - Page #"

Hope this helps. It's moving along for sure.

mgifford’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs review » Needs work

I think we're going to have to address this in 8.1.

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

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.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.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.

jonathanshaw’s picture

Title: Append the page number to the title » Allow global tokens (and therefore page numbers) in display title
Issue tags: -Needs beta evaluation +Needs reroll
jofitz’s picture

Assigned: mikeker » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.61 KB

Re-rolled.

Munavijayalakshmi’s picture

+++ b/core/modules/views/src/ViewExecutable.php
@@ -1828,6 +1828,9 @@ public function getTitle() {
+    // Allow global token substitutions

Comments should (noramlly) begin with a capital letter and end with a full stop / period .

Fixed and attached new patch.

mikeker’s picture

The last submitted patch, 26: 2509716-tests-only.patch, failed testing.

jonathanshaw’s picture

Addressing #18 would require extensive work, probably allowing to configure the page title separate from the view header.

I suggest it should be punted to a separate issue (or this patch moved to a separate issue), because what we have here is a ready-to-go, simple, effective enhancement. The current patch enables tokens in the title area, which before wasn't possible. It's a solid step forward.

Regarding #17.1 I notice that the LinkFormatter has
$link_title = \Drupal::token()->replace($item->title, [$entity->getEntityTypeId() => $entity], ['clear' => TRUE]);
i.e. it doesn't set an explicit langcode. There are not many examples of this in core to go by.

The langcode seems to be used by modules implementing hook_tookens. In core they tend to use a pattern like

  if (isset($options['langcode'])) {
    $url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
    $langcode = $options['langcode'];
  }
  else {
    $langcode = NULL;
  }

or

  if (isset($options['langcode'])) {
    $url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
    $langcode = $options['langcode'];
  }
  else {
    $langcode = LanguageInterface::LANGCODE_DEFAULT;
  }

So it looks like the langcode is optional and will tend to default sanely if omitted.

mikeker’s picture

@jonathanshaw, thank you for the review and for providing feedback on #17.1. From what you're saying it sounds like it's fine that this code does not provide a langcode.

Addressing #18 would require extensive work, probably allowing to configure the page title separate from the view header.

Agreed. And I believe this can be handled by the Metatag module, at least the part about the title tag being different from the h1 page title.

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.

Pancho’s picture

Category: Bug report » Feature request
Related issues: +#2888320: Add support for Token and plural in Views Global result summary plugin

Apart from the tests a small patch that still applies cleanly on 8.7.x-dev and works as advertised.

IMHO a feature request, as the optional header already supports global tokens which for accessibility is sufficient.
Still a nice improvement.

We might want to add plural support as well, similar to #2888320: Add support for Token and plural in Views Global result summary plugin. We can do that in a followup, however.
If 8.7.x tests are passing this should be RTBC.

andrewmacpherson’s picture

#9:
I agree with this. Putting the page number in the <title> is highly desirable.
It's definitely worth updating the default views config, for new installs, but we can leave existing sites alone. That can be deferred to a follow-up issue if needs be.

#11:

More specifically than WCAG success criterion 2.4.2 Page Titled at level A, there is SC 2.4.8 Location at level AAA. This is certainly something we can treat as level-A though; some level-AAA criteria are really just refinements of a more general concept at level-A.

A relevant WCAG technique is G127: Identifying a Web page's relationship to a larger collection of Web pages. This is close to the example 3 there (chapters of a textbook).

#28-29:
These suggest a follow-up should be filed for #18, to allow the visible heading and <title> to differ, so this should be filed before RTBC.

#33:

IMHO a feature request, as the optional header already supports global tokens which for accessibility is sufficient.

I don't really follow what this means. The issue title says it's about allowing global tokens, but #33 says it already supports global tokens.

This could do with an issue summary update, about what is actually being changed here. In particular, the word "title" is ambiguous, as some comments are talking about the (visible) view title plugin, but it's clear that @DuaelFr is talking about the HTML <title> element. I think these are tightly coupled at present?

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.

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.

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.

mgifford’s picture

Issue tags: +vpat

Linking open issues from the CivicActions Accessibility - VPAT.

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.

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.

mgifford’s picture

Issue tags: +wcag242
needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
150 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.

Bhanu951 made their first commit to this issue’s fork.

Bhanu951’s picture

Rerolled patch 2509716-tokens-in-page-title.patch from #26 against 10.1.x and updated test.

Bhanu951’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Was previously tagged for issue summary update and follow up which still appear to need and happen.

Also if there is a UX change before/after screenshots will be needed

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.