Problem/Motivation

Tokens for Drupal 5 & 6 came with a token for the Page Number. This exposed the ?page=1 part of the URL (for pages with pagers on them) as a single numeric token which could be used with modules such as Page Title. Google tends to get really annoyed with different pages having the same URL, so the combinaton of Page Title and the page-number token can really help View's pages with Pagers enabled on them to not cause SEO damage to a website.

Proposed resolution

Add [site:page-number] to system tokens.

This patch has been rerolled several times, it was originally from "Token's DRUPAL-6--1 branch".

Steps to test:

  • Requires the token module.
  • Click 'Browse available tokens' from somewhere in the UI
  • Expand the 'Site Information' section. With patch, a 'Page Number' token will be visible - [site:page-number]
  • Add the token somewhere, view whatever you've added it to, then verify it detects ?page=0, ?page=1 etc. from the URL

Remaining tasks

- Review patch.

User interface changes

New token, but no CSS/JS/HTML changes.

API changes

None.

Data model changes

None.

Comments

wulff’s picture

Version: 7.x-dev » 8.x-dev
Component: other » system.module
StatusFileSize
new1.11 KB

It looks like a break statement is missing.

I have attached a patch which fixes that and attempts to make the page number extraction a little easier to read.

Also, I guess by now this is a feature request against 8.x.

nicholasthompson’s picture

I'd personally prefer this to get into D7... Bearing in mind this is a feature that was in the Token's module and hasn't been ported over to the D7 module. I understand there is a code freeze for new features though.

If it wont make it into D7, I'll simply have to release a tiny module for it :)

dave reid’s picture

There will be no problem adding this to token.module for D7 though. Most people will still want the contrib module for the nice token UI.

dave reid’s picture

Isn't this just a duplicate of #224262: Add Page Number token? Tokens were never in core for D5 and D6, so not sure how they could be "missing" now.

nicholasthompson’s picture

Tokens themselves weren't "core", however since about Tokens 1.12, [page-number] has been a valid token.

As you say, if it doesn't make it into Core then we can add it to the Token-7.x project, but in that case it seems Core has a kind of "half" implementations of Tokens which requires the addition of a contrib module to complete.

In any case, this is a very small/minor change so if it makes it into core, fantastic - but if not, it's not the end of the world :)

Cheers,
Nick

dave reid’s picture

Yeah, 7.x is already closed to feature requests and token.module for D7 already has [current-page:page-number], so we're good until 8.x.

tr’s picture

StatusFileSize
new932 bytes

Re-rolled for D8 and reposted to get the test bot to recognize it.

ramkumarr’s picture

StatusFileSize
new952 bytes

The Previous Patch doesn't apply to the latest drupal folder structure.
I have recreated the patch and attached it.

tr’s picture

8: 619704-page-token.patch queued for re-testing.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Needs work
+++ b/core/modules/system/system.tokens.inc
@@ -169,6 +173,10 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
+          $replacements[$original] = preg_match('/^\d+/', $_GET['page'], $match) ? $match[0] + 1 : '';

The $_GET superglobal should be replaced since #1998638: Replace almost all remaining superglobals ($_GET, $_POST, etc.) with Symfony Request object landed.

slivorezka’s picture

StatusFileSize
new995 bytes

The Previous Patch doesn't apply.
I have recreated the patch and attached it. (not use $_GET param).

jhedstrom’s picture

Status: Needs work » Needs review
jhedstrom’s picture

Issue tags: +Needs tests

Adding a test here would be nice. See TokenReplaceUnitTest. Since this is technically a feature request, I'm guessing it has to get bumped to 8.1.

slivorezka’s picture

StatusFileSize
new2.18 KB

I have added a patch with UnitTest .

jhedstrom’s picture

Tagging for beta phase evaluation (https://www.drupal.org/node/2373483). The patch and test look good to me, just unsure about whether this can go into 8.0 or not.

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should 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.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.

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.

wturrell’s picture

Version: 8.3.x-dev » 8.4.x-dev
Issue summary: View changes
StatusFileSize
new2.88 KB

- I've rerolled the patch against 8.3.x, but I'm assuming this will only be eligible for 8.4
- I've tested with the metatag module, and that the [site:page-number] token becomes available with the patch applied
- Updated the issue summary with instructions
- TokenReplaceUnitTest.php no longer exists, testSystemSiteTokenReplacement() is now in TokenReplaceKernelTest.php
- Passes tests locally, will see how it fares with testbot.
- Could use extra pairs of eyes on the systems.token.inc changes, there was an element of guesswork involved.
- Can we lose the 'Needs beta evaluation' tag now?

wturrell’s picture

Issue summary: View changes

(fix missing bits of issue summary)

Munavijayalakshmi’s picture

StatusFileSize
new2.83 KB

The patch did not longer apply, so I have re-rolled it.

Status: Needs review » Needs work

The last submitted patch, 22: missing_page_number_token-619704-22.patch, failed testing.

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.

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.

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.

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.

mstrelan’s picture

Status: Needs work » Postponed (maintainer needs more info)

Considering token contrib module has [current-page:page-number] is this still required? Setting to PMNMI to determine if people still want this in core.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Since there's been no follow up and as mentioned there is a contrib module. Slimmer core stronger core :)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.