I wanted a way to conditionally display the URL I was using drupal_url() for, but mainly because I am using it on views to display action buttons next to the row. The url on its own was useful, but then I realized I could make it simpler if I also have a drupal_link() that also works with the access, by only outputting something if it has access to it.

CommentFileSizeAuthor
#3 2942287-n3.patch4.97 KBhanoii
#2 2942287-n2.patch2.29 KBhanoii

Comments

hanoii created an issue. See original summary.

hanoii’s picture

Title: improve drupal_url with an optional access check and add drupal_link as well » Improve drupal_url with an optional access check and add drupal_link as well
Status: Active » Needs review
StatusFileSize
new2.29 KB

Attached is the patch.

hanoii’s picture

StatusFileSize
new4.97 KB

Improved patch + tests.

hanoii’s picture

Hmm, apparently tests are not properly configured for 2.x?

hanoii’s picture

Also, not hugely important, but on twig_tweak_test.info.yml, I think the dependencies are wrong:

dependencies:
  - drupa:twig_tweak
  - drupal:node

should be

dependencies:
  - twig_tweak:twig_tweak
  - drupal:node

Will submit a patch if interested, it works anyway. Just noting here for now.

chi’s picture

apparently tests are not properly configured for 2.x

Right, just configured it.

chi’s picture

I think the dependencies are wrong

Yes, this needs a to be fixed independently.

  • Chi committed 16b0cc1 on 8.x-2.x authored by hanoii
    Issue #2942287 by hanoii: Improve drupal_url with an optional access...
chi’s picture

Status: Needs review » Fixed

Committed with minor cleanups. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

anybody’s picture

@hanoii I just saw that there's no documentation about the differences and when to use the twig_tweak methods added here instead of the core twig methods.

Could you maybe add that information to the README in this follow-up? #3582180: Document twig_tweak's drupal_link() / drupal_url() vs. url() / link() in Drupal core difference That would be great! :)