checking access to link in twig modern drupal

This returns the path whether the current user has access or not.

path('entity.user.edit_form', {'user': uid}, {'query': {'destination': path('<current>')

Twig Tweak module does have drupal_path or such that will check access, but it doesn’t take routes?


Best suggestion in forums is to do a hasPermission check in the if statement:

but no, no, no. Drupal has excellent fine-grained permissions and absolutely knows if i have access to edit one particular user or not, that is not necessarily identifiable with broad-level permissions.

Sigh again.

No option to tell it to be sensitive to access control for path() or link() or url() twig functions.

Again, Twig Tweak does do this in their alternate path-to-URL functions.

Improve drupal_url with an optional access check and add drupal_link as well [#2942287] |

Anyway, the place i inherited this attempt to do ridiculous things in a twig template was in a view field rewrite thing, so while the desire to create own links was still there, for the redirect back to the current page and to also do a cancel/delete link, we could use the edit link that Views makes available as a field, output as text, for what we check in our if statement on whether to view the edit/delete links.