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

Use Templating Component without "templating" service #457

Merged
merged 6 commits into from
Jan 17, 2018

Conversation

covex-nn
Copy link
Contributor

@covex-nn covex-nn commented Dec 25, 2017

I am targeting this branch, because this is backward compatible feature.

See #456

Changelog

### Added
- Added `symfony/asset` and `symfony/templating` dependencies
- Added new service `sonata.templating` for use in place of `templating`

### Changed
- Referencing templates using Twig namespaced syntax

### Removed
- Removed tag `templating.helper` from `sonata.block.templating.helper` service

Subject

This is first step to switching from Templating Component to using Twig directly. The following two steps are described in #456. This PR will allow to run SonataBlockBundle without activating templating extension in framework.

If this PR will be accepted, all other sonata bundles, that use SonataBlockBundle, could be updated too: services will have to use sonata.templating service instead of templating and templates must be referenced using Twig namespaced syntax

@SonataCI
Copy link
Collaborator

Could you please rebase your PR and fix merge conflicts?

@SonataCI
Copy link
Collaborator

Could you please rebase your PR and fix merge conflicts?

@covex-nn covex-nn changed the title Use Templating Component without "templating" service [WIP] Use Templating Component without "templating" service Dec 27, 2017
@covex-nn covex-nn changed the title [WIP] Use Templating Component without "templating" service Use Templating Component without "templating" service Dec 27, 2017
@SonataCI
Copy link
Collaborator

SonataCI commented Jan 7, 2018

Could you please rebase your PR and fix merge conflicts?

use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator as FrameworkTemplateLocator;

/**
* @deprecated since 3.9, to be removed with 4.0.
Copy link
Member

Choose a reason for hiding this comment

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

why? its new

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've created new service sonata.templating, to start migrating from templating to twig service without BC breaks in 3.x branch. sonata.templating, like templating service, has 3 arguments: twig, sonata.templating.name_parser and sonata.templating.locator. This new class is sonata.templating.locator service.

It is a new class, yes. It is needed in 3.x branch to be sure, that everything will be fine after deprecating of symfony/templating component. But this new class should not be used by other services, because it will be deleted in master branch (if PR will be merged, of course) accordingly with stage 2 of a plan, described in #456

So, it is new and deprecated at the same time.

use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser as FrameworkTemplateNameParser;

/**
* @deprecated since 3.9, to be removed with 4.0.
Copy link
Member

Choose a reason for hiding this comment

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

why? its new

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above. But this class is sonata.templating.name_parser service

@kricha
Copy link

kricha commented Jan 8, 2018

Maybe this need to be done in CoreBundle? And then can be reused in other sonata bundles?
@OskarStark @greg0ire @core23 @jordisala1991

@greg0ire
Copy link
Contributor

greg0ire commented Jan 9, 2018

@aLkRicha what do you mean by reused? This migrations needs to be done on all bundles, right?

@covex-nn
Copy link
Contributor Author

covex-nn commented Jan 9, 2018

@jordisala1991 the second argument of Sonata\AdminBundle\Block\AdminListBlockService (abstract parent class for all Blocks) is Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating.

So, we cannot just change EngineInterface to Twig\Environment in 3.x branch - this is BC break. And there is nothing to deprecate here, except may be AbstractBlockService itself.

@kricha
Copy link

kricha commented Jan 9, 2018

@covex-nn please, answer my question ☺️ #457 (comment)

@covex-nn
Copy link
Contributor Author

covex-nn commented Jan 9, 2018

@aLkRicha CoreBundle does not use templating service, BlockBundle does. The main purpose
of sonata.templating is to replace templating as a second argument of AdminListBlockService class in 3.x branch without BC breaks. If some other bundle uses templating, then there could be another way how to decouple from symfony/templating and how to use twig service instead of templating.

So, BlockBundle is a right place for a new sonata.templating service. May be sonata.templating should be in separate repository (not in SonataCoreBundle and not in SonataBlockBundle), but i am not sure about it (it is too complicated)

@jordisala1991
Copy link
Member

jordisala1991 commented Jan 9, 2018

@covex-nn but you can remove the type hint, and check if the instance passed is a EngineInterface or TwigEnv.. and if not throw an exception.. and that is not BC break

@covex-nn
Copy link
Contributor Author

covex-nn commented Jan 9, 2018

@jordisala1991 i used http://symfony.com/doc/current/contributing/code/bc.html to determine what change is allowed and what is not. Removing type hint of an argument of a public method is not allowed there. I thought it is a BC break.

Anyway, removing type hint could be done only after all template references in all bundles will be guaranteed switched from "templating syntax" to "twig namespaced syntax", i.e. only in master branch, in next major release. But i hoped to run SonataAdminBundle with Flex with in 3.x branch.

If "removing type hint of an argument" is not BC break, than my plan is not good enough, and there will be 2 stages, not 3.

@jordisala1991
Copy link
Member

Wow, they really consider it bc break, althought we have done it several times, and I am not sure why they consider a bc break, because it does not break anything (if done correctly) . Wdyt @greg0ire?

@greg0ire
Copy link
Contributor

Removing the type hint of a method is a BC break for extending classes (they may only widen it).

@jordisala1991
Copy link
Member

https://3v4l.org/s6f92

It throws a warning but it works, anyway if we consider it BC break we cannot do what I said.

@greg0ire
Copy link
Contributor

Warning are BC breaks... Even strict standards are. That's why classes / methods should be final

@covex-nn
Copy link
Contributor Author

covex-nn commented Jan 10, 2018

I've updated issue #456, i added removing type hint for second argument of Sonata\AdminBundle\Block\AdminListBlockService in current master. Both sonata.templating and twig services will be used in blocks. Future master branch will not contain sonata.templating service.

@greg0ire
Copy link
Contributor

The build fails on php 7.0

@OskarStark
Copy link
Member

The build fails on php 7.0

I restarted the build, as it was a race condition 👍

@kricha
Copy link

kricha commented Jan 16, 2018

do we really need there symfony/templating dep?

@covex-nn
Copy link
Contributor Author

@aLkRicha we need it in 3.x branch, because Templating Component is still used. It will be removed in master branch, if this PR will be accepted

@@ -11,7 +11,7 @@

namespace Sonata\BlockBundle\Test;

use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Sonata\BlockBundle\Templating\EngineInterface;
Copy link
Member

@jordisala1991 jordisala1991 Jan 17, 2018

Choose a reason for hiding this comment

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

This is the only “use” that you are replacing even though there are more references to EngineInterface on the project. Dont we need to replace all of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will replace all "use"s in master branch, if this PR will be accepted. Tests, that use Sonata\BlockBundle\Test\FakeTemplating show us, that when we use templating service, implementing Sonata\BlockBundle\Templating\EngineInterface, everything is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And we use sonata.templating instead of templating !

sonata.templating is Sonata\BlockBundle\Templating\TwigEngine, it implements Sonata\BlockBundle\Templating\EngineInterface.

@jordisala1991 jordisala1991 merged commit 5acea15 into sonata-project:3.x Jan 17, 2018
@jordisala1991
Copy link
Member

Lets pull the trigger, great work @covex-nn

@covex-nn
Copy link
Contributor Author

covex-nn commented Jan 17, 2018

@jordisala1991 please do not release it right now. I realized, that i should not remove tag from templating helper. Functions {{ sonata_block.includeStylesheets(...) }} are not available in 3.x. I will create PR to fix that. Sorry

@covex-nn
Copy link
Contributor Author

covex-nn commented Jan 19, 2018

I've found, that it is not so important, but anyway removing templating.helper tag is BC break: templating.helper tag is used for php templating engine:

<?php echo $view['sonata_block']->includeStylesheets('css/style.css'); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants