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.
Problem/Motivation
There should be a link to open the reference to available tokens in the Configure block dialogue.
That way you can consult it, when you want to add a token into the block title, for example.
Proposed resolution
Add code to generate the link into the token_form_block_form_alter function and adjust the weight to position it below the text field.
Remaining tasks
User interface changes
Link will be displayed below the text field, if possible.
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#19 | browse_available-2834366-20.patch | 1.66 KB | VladimirMarko |
#19 | interdiff-2834366-14-20.txt | 1.96 KB | VladimirMarko |
#19 | browse_available-2834366-20-test-only.patch | 749 bytes | VladimirMarko |
Comments
Comment #2
VladimirMarko CreditAttribution: VladimirMarko at MD Systems GmbH commentedComment #3
AaronBaumanI came here to post a patch for the same issue.
Let's get it fixed!
Did you assign to yourself because you're working on a patch?
Otherwise, you should unassign to indicate that it's ready to be picked up by anybody.
Comment #4
BerdirHe did, but he also left for the weekend already. If you have a patch, post it.
Comment #5
AaronBaumanok, here it is
Comment #6
BerdirThat's... an interesting use of #description.
Can you post a screenshot of how that looks?
Also needs tests
Comment #7
AaronBaumanI was surprised that this worked at all:
The 'browse' link is appended to div.description
The problem with a more standard approach is that "Title" field doesn't have a #weight during form_alter, so it's not straightforward to situate a new element between the first 2 fields.
This approach was more expedient than, e.g. implementing a process callback.
What would a test look like for this?
There aren't any tests for the other 'browse' link implementations for me to crib.
Comment #8
BerdirThat looks quite nice. thanks. The problem with it might be that it won't work so well for a right to left language like russian. But probably not a huge deal if the link is before the text.
We have \Drupal\token\Tests\TokenBlockTest already. So basically, what we need to do is on the page where we edit the block, that we add an assertLink() that makes sure the link is displayed there. So it should be like a single additional line.
Comment #9
VladimirMarko CreditAttribution: VladimirMarko at MD Systems GmbH commentedI am missing the space between "tokens." and "Browse", when I apply the patch.
It says "This field supports tokens.Browse available tokens."
Comment #10
BerdirYes, I suspected this would happen.
We could try something like t('This field supports tokens. @browse_tokens_link') and then pass in the render array like that, but we probably need to render it ourself then with \Drupal::service('render')->render()
Comment #11
VladimirMarko CreditAttribution: VladimirMarko at MD Systems GmbH commentedFixed by using a placeholder as suggested.
There was no need to use render().
Also updated the associated test with two lines of assertions.
Comment #14
VladimirMarko CreditAttribution: VladimirMarko at MD Systems GmbH commentedAdded the \Drupal::service('renderer')->render() call. There are no more exceptions in my local test.
Comment #15
VladimirMarko CreditAttribution: VladimirMarko at MD Systems GmbH commentedForgot the test only patch. Here it is.
Comment #18
BerdirComment is too long.
Remove @todo left-over.
remove the old commented out line.
use short array syntax
#prefix stuff isn't needed, just = t(...);
Comment #19
VladimirMarko CreditAttribution: VladimirMarko at MD Systems GmbH commentedI made the required changes.
Comment #22
AaronBaumanNice, looks good to me.
Comment #24
BerdirAgreed, committed.