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
Currently, the flag links are rendered directly and without the use of the theme layer. This makes it difficult to style flag links.
Proposed resolution
Implement hook_theme and a theme function or template for flag links.
Remaining tasks
Create patch.
User interface changes
None, although an additional CSS class may be applied to the flag link.
API changes
Flag links would be themeable.
Comment | File | Size | Author |
---|---|---|---|
#11 | interdiff-2463365-10-11.txt | 851 bytes | martin107 |
#11 | flagTemplate.2463365.11.patch | 1.98 KB | martin107 |
| |||
#10 | flagTemplate.2463365.10.patch | 2.07 KB | socketwench |
|
Comments
Comment #1
joachim CreditAttribution: joachim commentedThere's a template on 7.x that we should use as a starting point, though we should also trawl through the issue queue as there have been various issues over the years to do with limitations of the theming approach.
Comment #2
socketwench CreditAttribution: socketwench commentedAfter some discussion on Twitter, the preferred way forward for D8 is to implement a Twig template for nearly all theming as opposed to theme functions. Since we used a template before, I see no reason to change that.
Unfortunately, there doesn't seem to much for Twig in Examples. Core book module seems to have some promise to figure out how to use Twig.
Comment #3
joachim CreditAttribution: joachim commentedI've been doing a fair bit with twig over on Garland. It's actually pretty easy!
Comment #4
joachim CreditAttribution: joachim commentedThe D7 version of the theming for this was removed with commit eaa98bf807b1ed60557ee6be0582cb0a36b4604d -- that should be studied when tackling this issue.
Comment #5
martin107 CreditAttribution: martin107 commentedjust mapping eaa98bf807b1ed60557ee6be0582cb0a36b4604d back to an issue
#2651502: Remove flag.js
and patch
https://www.drupal.org/files/issues/2651502.7.removeThemeFolder.patch
Comment #6
martin107 CreditAttribution: martin107 commentedI have taken a little look at this tried assembling pieces of the solution together
and I find myself coming up short perhaps someone can nudge me in the right direction.
here is the html of typical link
here is the point in ActionLinkTypeBase in which the render array is generated and then modified.
so we could swap out this line
and replace it with a new #theme' called say 'flag-action-link' and then we could do what we want in corresponding twig file.
BUT below I am including the render array as it stands today....
The question I cannot answer is how can we deal with token part html the
token=VuC2C-Q1BoU21Rg54EPwcYvrCkN5w6lFOobPxN_FbQ8"
from the another perspective deal with #access_callback
Any prods in the right direction would be appreciated.
Comment #7
BerdirRelated: http://drupal.stackexchange.com/questions/188237/how-do-i-customize-the-... for possible use cases.
I think we should keep the #type, there would be quite a bit of code to copy otherwise.
Maybe we could specify a wrapper template that by definition just prints the link? If we can find a nice way to add some classes and other attributes to the link itself then that should be enough?
Comment #8
joachim CreditAttribution: joachim commentedOne thing we need to check is the confirmation messages that JS flags show on D7.
Comment #9
socketwench CreditAttribution: socketwench commentedThat's basically what I was thinking we would do from the start...
Comment #10
socketwench CreditAttribution: socketwench at FFW commentedHere's a first go at implementing the template.
Comment #11
martin107 CreditAttribution: martin107 commentedI think the patch from #10 is a good solution.
In #6 I included the generated html for the link ... below I am including what it looks like with the patch applied - and theme debug turned on.
The token comes through correctly and the only difference I can see is the inclusion of a empty alt attribute.
My patch is trivial - it deletes spaces from an empty line and adds a newline to the end of a file.
Comment #13
socketwench CreditAttribution: socketwench at FFW commentedThanks for the fixes, Martin!
Comment #14
martin107 CreditAttribution: martin107 commentedAh thanks for teaching me the token trick.