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.
When using the [view:url] token when there is no URL for the current display and no linked display with a URL can be found (i.e. you only have a block display), an exception is thrown:
InvalidArgumentException: You cannot create a URL to a display without routes. in Drupal\views\ViewExecutable->getUrl()
Expected behaviour: empty token value, no exception.
Comment | File | Size | Author |
---|---|---|---|
#13 | view_url_token-2804375-13.patch | 3.69 KB | Lendude |
#13 | interdiff-2804375-7-13.txt | 963 bytes | Lendude |
#7 | view_url_token-2804375-7.patch | 3.66 KB | Lendude |
#7 | view_url_token-2804375-7-TEST_ONLY.patch | 2.83 KB | Lendude |
#2 | view_url_token-2804375-2.patch | 868 bytes | Lendude |
Comments
Comment #2
LendudeHere is a fix for this, this still needs tests obviously.
Comment #3
dawehnerShould we maybe fix getUrl()?
Comment #5
LendudeWell it seems to me that getUrl() is doing exactly what it's advertising:
So I'd say it's up to the code utilising getUrl to properly handle any exceptions. Changing getUrl would feel more like an API change, but *shrug*
Comment #6
dawehnerFair point, well then let's catch exceptions :)
Comment #7
LendudeHehehe, yeah lets :)
Test and a fix. No interdiff, totally different approach, it's now catching exceptions instead of trying to make sure there will be none.
Comment #9
marcvangendThanks Len.
Do we really want to silently catch the exception and do nothing? Or would it be better to warn that the token was requested but the value could not be retrieved?
Comment #10
dawehnerIt is sad that we don't have a more specific domain exception :(
Well, we could replace it with an empty string ... isn't that what is expect in token for this case?
Comment #11
marcvangendI'm not sure about an empty string, the resulting string would probably not be any better than a string with a literal token in it. When I was debugging this with Len, we found that it happened only because the
[view:url]
token was actually being used (in the empty text, in my case). Basically it was a misconfigured view, so I think a warning message for the admin would be appropriate.Comment #12
dawehnerInteresting, well we can certainly provide a logging message using
watchdog_exception()
I would just follow what tokens usually do.
Comment #13
LendudeI looked around a bit and in most cases this just means an empty token. I think a watchdog message is a little too much for a misconfigured token. It would have helped with debugging in our case but that was mostly because we were getting a fatal-500-in-the-background-ajax-call.
I think just making the token empty is a clear sign of what's going on, "we have no data to replace the token with".
Comment #14
dawehnerThis works for me
Comment #15
alexpottCommitted e12c685 and pushed to 8.3.x. Thanks!
Setting to patch to be ported for eventual cherry-pick to 8.2.x once 8.2.0 is released.
Comment #17
alexpottCommitted 38adfc2 and pushed to 8.2.x. Thanks!