Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-31499: Implemented ez_path/ez_url Twig functions #3000

Merged
merged 7 commits into from
Mar 24, 2020

Conversation

adamwojs
Copy link
Member

@adamwojs adamwojs commented Mar 19, 2020

Question Answer
JIRA issue EZP-31499
Bug/Improvement no
New feature yes
Target version master
BC breaks no
Tests pass yes
Doc needed yes

Implemented ez_path/ez_url functions which allows to generating path/url in Twig templates from the objects of the following classes

  • \eZ\Publish\API\Repository\Values\Content\Content
  • \eZ\Publish\API\Repository\Values\Content\ContentInfo
  • \eZ\Publish\API\Repository\Values\Content\Location
  • \eZ\Publish\Core\MVC\Symfony\Routing\RouteReference

It's replacement for build-in path/url twig functions which no longer accept anything else then string as first argument:

Demo: https://gist.github.com/adamwojs/3056d518ac41b0d1e8a9937e4eece069

TODO:

  • Implement feature / fix a bug.
  • Implement tests.
  • Fix new code according to Coding Standards ($ composer fix-cs).
  • Ask for Code Review.

$routeName = $object->getRoute();
$parameters += $object->getParams();
} else {
throw new InvalidArgumentException('$object', 'Unsupported class: ' . get_class($object));
Copy link
Contributor

@emodric emodric Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this would not throw, rather somehow allow using these methods in other packages like Netgen Tags, which also used path and url to generate links to tag objects.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be useful extension point, we will think of it. For now in all cases which are not supported by eZ Platform I've added fallback to replacement proposed by symfony-cmf/routing.

// cc @bdunogier

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this will be enough for now. I will test once you merge this.

@adamwojs adamwojs force-pushed the ezp_31499_ez_path_ez_url branch from 4076da9 to f926d08 Compare March 20, 2020 13:32
Comment on lines -17 to -20
if ($name instanceof RouteReference) {
$parameters += $name->getParams();
$name = $name->getRoute();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work anymore. In theory we could provide support for syntax

$this->urlGenerator->generate('', [
    RouteObjectInterface::ROUTE_OBJECT => $routeRef
])

but it will require to impl. \Symfony\Cmf\Component\Routing\ChainedRouterInterface which seems to be overkill for me.

@lserwatka lserwatka merged commit 256b3e0 into master Mar 24, 2020
@lserwatka lserwatka deleted the ezp_31499_ez_path_ez_url branch March 24, 2020 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

7 participants