Closed iherak closed 9 months ago
It should be generated through the router, so siteacess should already be there and no need to take care of it manually. If we implement it through a method, it can be generated on demand.
What I meant was, what's the usecase for having the URL alias in the location object directly? You can just as well use location.id
with ez_urlalias
route to generate a correct link by using path
or url
Twig functions.
Well, it could ve just an additional commodity for the developer, so you don’t need to inject the router constantly, and instead have the URL available out of the box.
Okay, so then that's not the URL alias, it's an URI (and that's not just semantics). Also, do you get the relative or the absolute URI? Do you support query params or fragments?
Also, out of the curiosity: how often do you actually generate the URLs in PHP (as opposed to Twig) that you need to inject the URL generator/router constantly in your services?
Both relative and absolute, and query parameters as well. Fragments probably not needed, from my POV it would be simpler to just concatenate than to have another argument.
I'm currently thinking something like (simplified):
function getUrl(array $queryParams): Url
class Url
{
public $relative;
public $absolute;
public function __toString()
{
return $this->relative;
}
}
Then you could write from Twig:
{{ location.url }}
{{ location.url.absolute }}
{{ location.url(params) }}
Also, out of the curiosity: how often do you actually generate the URLs in PHP (as opposed to Twig) that you need to inject the URL generator/router constantly in your services?
Actually quite often, the last use-case was JSON endpoint for a React app.
Actually quite often, the last use-case was JSON endpoint for a React app.
Okay, fair enough, for PHP it can be useful. As for Twig, how is this, which is already possible:
{{ path(location) }}
{{ url(location) }}
{{ url(location, params) }}
different from your example in terms of simplicity?
I'd rather prefer using path
and url
functions, since it's closer to the Symfony way of using the router.
Yup, that pretty much looks the same :)
We've had requests for this too. Often when dealing with locations (using APIs in PHP or over REST) people have a need for the url alias as well, or techanlly being able to get the final URI (more) easily. But as comments above says, it easily gets a bit complicated in terms of params and absolute vs relative. Unsure if this has been on @bdunogier's radar yet and/or if he has some thoughts about it :)
We're ATM quite busy with v3 release, but I plan to look into this again once that is finished.
@iherak do you still need this? :))
Yup, I still see a use for this. As @pspanja and @hknezevic mentioned, mostly valuable for usage through PHP, and that was the original intent of this issue :)
Throwback to
$node.url_alias
:)What's the usecase? How would you generate the links in regards to siteaccess name being in the URL? We'd need a special route to generate the link with Symfony Routing.
It could be done currently with
path(ezpublish.rootLocation) ~ location.url_alias
, but that seems clunky at best.