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
Comment #1
wulff commentedIt 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.
Comment #2
nicholasthompsonI'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 :)
Comment #3
dave reidThere 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.
Comment #4
dave reidIsn'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.
Comment #5
nicholasthompsonTokens 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
Comment #6
dave reidYeah, 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.
Comment #7
tr commentedRe-rolled for D8 and reposted to get the test bot to recognize it.
Comment #8
ramkumarr commentedThe Previous Patch doesn't apply to the latest drupal folder structure.
I have recreated the patch and attached it.
Comment #9
tr commented8: 619704-page-token.patch queued for re-testing.
Comment #10
jhedstromThe
$_GETsuperglobal should be replaced since #1998638: Replace almost all remaining superglobals ($_GET, $_POST, etc.) with Symfony Request object landed.Comment #11
slivorezkaThe Previous Patch doesn't apply.
I have recreated the patch and attached it. (not use $_GET param).
Comment #12
jhedstromComment #13
jhedstromAdding 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.Comment #14
slivorezkaI have added a patch with UnitTest .
Comment #16
jhedstromTagging 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.
Comment #20
wturrell commented- 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?
Comment #21
wturrell commented(fix missing bits of issue summary)
Comment #22
Munavijayalakshmi commentedThe patch did not longer apply, so I have re-rolled it.
Comment #36
mstrelan commentedConsidering token contrib module has
[current-page:page-number]is this still required? Setting to PMNMI to determine if people still want this in core.Comment #37
smustgrave commentedSince there's been no follow up and as mentioned there is a contrib module. Slimmer core stronger core :)