Closed (fixed)
Project:
Drupal core
Version:
8.3.x-dev
Component:
base system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
27 Aug 2016 at 20:18 UTC
Updated:
13 Sep 2016 at 20:34 UTC
Jump to comment: Most recent
Comments
Comment #2
cilefen commentedURL generation is a service. From core.services.yml:
UrlGeneratorInterface has ::getPathFromRoute.
#2491981: There are too many ways to generate URLs and links
Comment #3
amitaibuI missed that one. Great, thanks :)
Comment #4
dawehnergenereteFromRouteis the right method to use, as this is exactly what\Drupal\Core\Urlis using.Comment #5
dawehnerWell, IMHO you should not mock the constructor of a value object, which Url mostly is.
Url::fromRouteconceptually is just another and more readable name fornew Url().Comment #6
amitaibu> conceptually is just another and more readable name for new Url().
@dawehner, can you please clarify how would you do it than - how would I controll the return Value of the access check? Given the
accessManagerservice is under $this->isRouted()Comment #7
amitaibuAlso, seems that the
url_generatoris not equivalent, as it returns the generated URL (that is, a string) and not theUrlobject which I need to later execute$url->access()Comment #8
dawehnerAh, well, I would actually not use
$url->access()to be honest, but rather use the access manager directly.For me its too much responsibility in one class.
Comment #9
amitaibuYeah, I might have to do it, since I don't see an alternative that can be easily unit tested (as stated in #7
url_generatordoesn't allow me to use ::access().I'll close for now. I believe you folks have answered my questions, thanks!
Comment #10
dawehnerWhy do you not use,
$this->accessManager->checkNamedRoute($url->getRouteName(), $url->getRouteParameters())?Here is a though. An AccessCheckedUrl which wraps a URL with an access check when its printed out.
Comment #11
amitaibuI do, and it worked perfectly. It fitted my needs. Not sure about the use case of
AccessCheckedUrl- I think that when you reach the point you print something, you should already know if they passes access check or not (e.g. so you could show a different message if non printed out)