Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Simple request and should be possible with hook_block_view_alter() - perform token replacement on $block->title.
Comment | File | Size | Author |
---|---|---|---|
#15 | token_block-title-ui_15.patch | 709 bytes | kalabro |
#15 | 2013-02-21_18-06-00.png | 3.76 KB | kalabro |
#9 | 1515978-block-title-token-validation.patch | 1.67 KB | Dave Reid |
#2 | 1515978-block-title-tokens.patch | 4.89 KB | Dave Reid |
#1 | 1515978-block-title-tokens.patch | 1.35 KB | Dave Reid |
Comments
Comment #1
Dave ReidComment #2
Dave ReidWith tests this time.
Comment #3
Dave ReidCommitted #2 to Git: http://drupalcode.org/project/token.git/commit/f306b40
Comment #5
Triskelion CreditAttribution: Triskelion commentedI tried to use this capability with
Welcome [user:name]
in a block title, and it simply returned the text.Had to add
global $user;
to token_block_view_alter(), and change the call to token_replace to$block->title = token_replace($block->title, array( 'user' => $user ), array('sanitize' => FALSE));
to get it to work.It is necessary to decide which tokens this function should support, and to pass the required $data array to token_replace().
Comment #6
Dave ReidYou should be using [current-user:name]. The token [user:name] only makes sense when provided with a specific user.
Comment #7
Triskelion CreditAttribution: Triskelion commentedKudos! I have never had such a rapid response.
Point taken. However, if you are going to restrict the use to system tokens, it might be a good idea to add a token_tree element to the settings. The only list of tokens now available is at admin/help/token.
Token validation is not working because the #token_types array is empty, and
token_get_invalid_tokens_by_context
is bypassed (This might be a bug, since system tokens will never be validated if they are the only context permitted.).Great module, and thank you for the work you have done.
Comment #8
Dave ReidHrm, yeah it would be a bug if that validation is getting bypassed. It should still run for global token types.
Comment #9
Dave ReidPatch attached that ensure that if #token_types is set but to an empty array, it should still run token validation.
Comment #10
Dave ReidCommitted #9 to Git. http://drupalcode.org/project/token.git/commit/f9016e7
As for the token browser, I've been holding off adding the browser to new places due to the performance concerns of having the browser everywhere. Once we solve #1684984: Support opening token browser in a jQuery UI dialog on demand we'll be able to add the token browser into this.
Comment #11
Triskelion CreditAttribution: Triskelion commentedThanks again Dave. I've started following the token browser issue.
Comment #12
jlongbottom CreditAttribution: jlongbottom commentedNode tokens do not seem to be working, but Current Page tokens do.
ex:
[node:title] - not working
[current-page:url:args:value:1] - working
Comment #13
Dave ReidAs expected. There's nothing currently that we do to determine what types of data we have in a reliable fashion to pass into token_replace() in this context aside from global non-context tokens like current-page.
Comment #15
kalabroVery cool! Could we make it more easy for site builders to see which tokens are supported?
Looks good with admin theme fix: #1859452: Dialog loads default theme CSS breaking admin theme
Comment #16
Dave Reid@kalabro: Can you please post this as a follow-up separate issue rather than re-opening an issue that's already been closed for half a year?
Comment #17
francescosciamanna CreditAttribution: francescosciamanna commented#6 Solution works great for me!
[current-user:name] it's enough to do the job in the Block title!
Comment #20
Dave ReidComment #23
Dave Reid