Closed (fixed)
Project:
Flag
Version:
5.x-dev
Component:
Flag core
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Nov 2024 at 22:36 UTC
Updated:
13 Dec 2025 at 08:19 UTC
Jump to comment: Most recent
Currently, there's no easy way to generate flag/unflag links in Twig templates. Developers need to inject the flag.link_builder service into their controllers or use service container directly to build these links. This creates unnecessary boilerplate code and makes templates less maintainable.
Add a new Twig extension that provides a `flaglink()` function to generate flag/unflag links directly in templates, similar to the existing `flagcount()` function.
Example usage:
{{ flaglink('node', node.id, 'bookmark') }}
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
introfini commentedMR added...
Comment #4
ivnishThanks!
1) Needs to fix pipeline issues https://git.drupalcode.org/issue/flag-3486524/-/pipelines/334145
2) Needs test for new twig function
Comment #5
ivnishComment #7
deaom commentedAdded test for twig extension, leaving to Needs work as phpstan for dependency injection still needs to be updated in the FlagLink.php
Comment #8
deaom commentedThe code in constructor of FlagLink twig extensions seems to be some legacy code, so rather then removing it, I've added the ignore next line for the Dependency Injection issue. Ready for review.
Comment #10
ivnish