Skip to content
New issue

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

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

Already on GitHub? # to your account

EZP-31851: Added Twig helpers that abstracts content rendering #115

Merged
merged 1 commit into from
Oct 6, 2020

Conversation

Nattfarinn
Copy link
Contributor

@Nattfarinn Nattfarinn commented Oct 5, 2020

Question Answer
JIRA issue EZP-31851
Type feature
Target eZ Platform version v3.3
BC breaks no
Doc needed yes

Still WIP (Todo section below), but open for brief review as main feature is done.

Based on a Proof of Concept/Experiment: ezsystems/ezpublish-kernel#1518

This PR provides two Twig helper functions and extensibility point for more:

  • ez_render_content - abstracts Content rendering via different rendering methods (default inline, subrequest, esi)
  • ez_render_location - abstracts Location rendering via different rendering methods (default inline, subrequest, esi)
  • ez_render - provides strategy (that comes with abstraction for extensibility) for sub-renderers (like one used directly by ez_render_content or ez_render_location helper)

Usage

Strategy used, default method:
{{ ez_render(content) }} 
Direct renderer, default method:
{{ ez_render_content(content) }} 
Direct renderer, subrequest method:
{{ ez_render_location(location, { method: "subrequest" }) }} 

Todo:

  • Tests, tests tests...
  • (Optional) Strategy for Location object with ez_render_location as helper.

Checklist:

  • Provided PR description.
  • Tested the solution manually.
  • Provided automated test coverage.
  • Checked that target branch is set correctly (master for features, the oldest supported for bugs).
  • Ran PHP CS Fixer for new PHP code (use $ composer fix-cs).
  • Asked for a review (ping @ezsystems/php-dev-team).

@Nattfarinn
Copy link
Contributor Author

Update: Investigating Travis issue right now.


$request = new Request();
$request->attributes->add([
'_controller' => 'ez_content:viewAction',
Copy link
Contributor

Choose a reason for hiding this comment

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

This way of referencing controllers is deprecated, double colon :: should be used instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 👍

eZ\Publish\Core\MVC\Symfony\Templating\RenderContentStrategy:
arguments:
$defaultMethod: 'inline'
$renderMethods: !tagged_iterator ezplatform.render.method
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to use tagged_locator instead, since we will always look for a particular render method anyway (using the key)?

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to use tagged_locator instead, since we will always look for a particular render method anyway (using the key)?

Locators are not the best choice when it comes to both strict types && DDD. This is gonna still be a generic objects container with get instead of something specifc. Until PHP has generics / STL support, the code is gonna usually cause a static analysis issue. Judging from this example alone...

I prefer to have an iterable and an array property with "strict" @param \Foo\Bar[] type. Since arrays itself are not strict, there's indeed not much of a difference. The difference is in DDD approach. My class should have no coupling on some ServiceLocator coming from a framework.It's a domain & responsibility mixup and a poor choice by Symfony (IMHO). iterable (or whatever more complex, but built-in type) seems to be cleaner.

Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

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

Seems like the existing tests are also failing.
Besides:

eZ\Publish\Core\MVC\Symfony\Templating\RenderContentStrategy:
arguments:
$defaultMethod: 'inline'
$renderMethods: !tagged_iterator ezplatform.render.method
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to use tagged_locator instead, since we will always look for a particular render method anyway (using the key)?

Locators are not the best choice when it comes to both strict types && DDD. This is gonna still be a generic objects container with get instead of something specifc. Until PHP has generics / STL support, the code is gonna usually cause a static analysis issue. Judging from this example alone...

I prefer to have an iterable and an array property with "strict" @param \Foo\Bar[] type. Since arrays itself are not strict, there's indeed not much of a difference. The difference is in DDD approach. My class should have no coupling on some ServiceLocator coming from a framework.It's a domain & responsibility mixup and a poor choice by Symfony (IMHO). iterable (or whatever more complex, but built-in type) seems to be cleaner.

eZ/Publish/SPI/MVC/Templating/RenderMethod.php Outdated Show resolved Hide resolved
@Nattfarinn
Copy link
Contributor Author

Travis CI issue fixed.

@adamwojs adamwojs changed the title (WIP) EZP-31851: Added Twig helpers that abstracts content rendering EZP-31851: Added Twig helpers that abstracts content rendering Oct 6, 2020
{
public function all(): array;

public function get(string $key, $default = null);
Copy link
Member

Choose a reason for hiding this comment

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

Type hints for implicitly mixed param and return would be good here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 👍. Obsolete comment.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 6, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Nattfarinn Nattfarinn force-pushed the ezp-31851-twig-helpers branch from a33cafc to 587719e Compare October 6, 2020 14:26
@Nattfarinn Nattfarinn merged commit 25f4e4a into master Oct 6, 2020
@Nattfarinn Nattfarinn deleted the ezp-31851-twig-helpers branch October 6, 2020 14:26
alongosz added a commit that referenced this pull request Jun 27, 2022
* IBX-2823: Added loadRelation method

https://issues.ibexa.co/browse/IBX-2823

* Update src/lib/Resources/settings/storage_engines/cache.yml

Co-authored-by: Konrad Oboza <konrad.oboza@ez.no>

* Update src/lib/Resources/settings/storage_engines/cache.yml

Co-authored-by: Konrad Oboza <konrad.oboza@ez.no>

* Fixed invalidate tags in removeRelation

* Added tests

* Update src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php

Co-authored-by: Paweł Niedzielski <pawel.tadeusz.niedzielski@gmail.com>

* Update tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php

Co-authored-by: Paweł Niedzielski <pawel.tadeusz.niedzielski@gmail.com>

* Update tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php

Co-authored-by: Paweł Niedzielski <pawel.tadeusz.niedzielski@gmail.com>

* Update tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php

Co-authored-by: Paweł Niedzielski <pawel.tadeusz.niedzielski@gmail.com>

* Update src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Update tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Update tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Update src/lib/Persistence/Legacy/Content/Handler.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Added deprecated info when destinationContentId is not passed

* Fixed phpdoc for removeRelation method

* Used const for relationId

* Fixed cs

* Update src/lib/Persistence/Cache/ContentHandler.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Update src/lib/Persistence/Legacy/Content/Handler.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Fixes after review

* Fixed ContentHandlerTest::testLoadRelation

Co-authored-by: Konrad Oboza <konrad.oboza@ez.no>
Co-authored-by: Paweł Niedzielski <pawel.tadeusz.niedzielski@gmail.com>
Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Development

Successfully merging this pull request may close these issues.

6 participants