Problem/Motivation
The list of all available tokens is a very useful resource but it is placed in the help text where users don't expect it.
Typically, the help text - as part of the documentation - is static and something users should only need to read once to figure out how a module works.
Other modules place their changing overviews of available or used items as pages in the report section; for example the lists of fields or views plugins provided by core modules. This is where I rather would expect the list of available tokens as well.
Proposed resolution
Place the table of available tokens as a page such as admin/reports/tokens and link to if from the help page.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#47 | tokenhelpwithtest-2782605-47.patch | 5.9 KB | vakulrai |
#45 | tokenhelp-2782605-45.patch | 3.47 KB | vakulrai |
#35 | token-move-list-of-available-tokens-2782605-34.patch | 2.69 KB | gaurav.kapoor |
#15 | 2782605-13.patch | 2.46 KB | rajeshwari10 |
#6 | 2782605-6.patch | 3.28 KB | yogeshmpawar |
Comments
Comment #2
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and at Blisstering Solutions commentedComment #3
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and at Blisstering Solutions commentedDone changes as per suggested.
Thanks,
Rajeshwari.
Comment #6
yogeshmpawarI have rerolled the patch to remove whitespace & new line warnings.
Comment #9
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and at Blisstering Solutions commentedComment #12
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and at Blisstering Solutions commentedComment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedIs it just me or is the list of available tokens here /admin/help/token (or here admin/reports/tokens when relocated) outdated.
My usecase is:
Send an e-mail when a comment has been written (via rules module):
From: {{comment.name.value}} Subject: {{comment.subject.value}}
works.
Regarding the list of tokens, there should be something like {{comment:edit-url}} but there isn't. Seems the whole comment namespace has been changed from D7 to D8 and the documentation available is outdated.
Or did I get something wrong? Thanks for a quick reply!
Comment #14
ifrik@dkynast,
your comment is a support request that has nothing to do with this issue.
You should make a separate issue for this (either as a bug or a support request). Alternatively you can ask for help at a more appropriate place such as on IRC.
Comment #15
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and at Blisstering Solutions commentedPlease review.
Comment #16
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and at Blisstering Solutions commented@ifrik
I have done changes as per the proposed solution.
Please review.
Comment #19
joachim CreditAttribution: joachim commentedThat's not the right way to create a link in text. The 'here' needs to be within the text, so the whole sentence can be translated, and the URL added in as a t() placeholder.
Is this the right permission? That means pretty much any visitor to the site can see this, including anon users who typically will have this permission.
IIRC, generating a token list is reasonably performance-heavy, so that would be a way to DDOS a site...
PS. Also, the link text should be descriptive, so 'here' shouldn't be the link. Something like 'You can also see [LINK]the list of all currently available tokens[LINK] on the site.
Comment #20
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedI guess this should be the correct way
Comment #21
joachim CreditAttribution: joachim commentedNope, that's not right either I'm afraid. That will also break translation!
You need to use a placeholder for the url, so the string passed to t() is completely hardcoded, eg
See the docs for https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/functi... for more details. (I can't find anything about this in the developer docs on d.o, which is either a big omission, or a google fail...)
Comment #22
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #23
joachim CreditAttribution: joachim commentedSorry, but we're now back to the problem with the first patch!
The *complete sentence* needs to be within the call to t().
To make a link, put the actual A element inside the t(), like in my example. Use a placeholder for the value of the href property.
This means also that the placeholder value should be a URL, not a link, so use the Url rather than Link class.
Finally, make sure the sentence is correctly punctuated and capitalized, and also to put a space after a parameter separating comma.
Comment #24
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #25
joachim CreditAttribution: joachim commentedThanks for persevering! :)
That's now the right approach for the use of the url in the translated string. A few things still need cleaning up though:
You don't need this import any more.
Stray space.
url() doesn't exist on D8. You want the Url class, and in particular https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Url.php/function/....
Also, the text should form a complete sentence. Currently, it will read:
> You can also see :Tokens ,The list of all currently available tokens on the site
What's wrong with this:
- there is a stray ':' before the word Tokens
- Tokens should be lower case
- there is a stray space after the word Tokens
- there is no full stop at the end
- the sentence doesn't make sense really. It should read "You can also see the list of all currently available tokens on the site."
Comment #26
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #28
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #30
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedI have added the required controller.Just need the Tokens info which should be displayed in the link.
Comment #32
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #34
joachim CreditAttribution: joachim commentedGetting there! :)
The list of tokens isn't here! See patch #3, which has it.
Missing newline.
This looks good!
Though this is causing a test failure, I think. The problem is that Url::fromRoute() returns an object, and the placeholder must be a string.
There should be a method on the Url class that outputs the url as a string.
Comment #35
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #37
joachim CreditAttribution: joachim commentedLooking good!
The test failures the latest patch is getting are all because the tests are expecting the help page to have the tokens list:
> fail: [Other] Line 40 of modules/contrib/token/src/Tests/Tree/HelpPageTest.php:
"The list of the currently available tokens on this site are shown below." found
In other words, it looks like the test needs to be updated too. The testing of the token list needs to be moved out of HelpPageTest, and into a new test case for the reports page.
Comment #38
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedThanks @joachim. But i am not able to understand what should be the exact logic to be used in new test. We have to modify the previous tests or create a new file with code for test case of report page??
Comment #39
joachim CreditAttribution: joachim commentedThe existing, failing test is called HelpPageTest. That makes it sound like it is testing just the help page. So adding a test for the new reports page here would be wrong, as the name of the test class would no longer be accurate.
So I would say:
- remove the parts of HelpPageTest that test the tokens list
- add a new test (ReportsPageTest?)
- adapt the removed parts and put them into the new test
Comment #40
BerdirThis is not inheriting from anything, so it needs documentation.
this should be injected as a service and assigned to $build['token_tree'] or so.
Then you can make the text as $build['info']['#markup'] or anything like that and drop the render call.
this also a needs a menu link so it shows up on /admin/reports.
I have no problem with just changing the help test, we can easily rename it to TokenHelpAndReportsTest or something.
Comment #41
RumyanaRuseva CreditAttribution: RumyanaRuseva at FFW commentedI find it inappropriate to move the token list into Reports. The reports page shows usage and statistics, and not all available functionality in the site. In your field list example, the Reports page shows which fields have actually been added in the entities, and it does not show all available field types which you can add.
Help is a very appropriate section for the token list.
If you're concerned that people may not find the help page, we might add a link to it from /token/tree pages.
Comment #42
vakulrai CreditAttribution: vakulrai as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedAdding a patch covering the changes suggested by #40.
Comment #43
vakulrai CreditAttribution: vakulrai as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedAdding a patch covering the changes suggested by #40.
Comment #45
vakulrai CreditAttribution: vakulrai as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedComment #47
vakulrai CreditAttribution: vakulrai as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedAdding patch with test.