-
Notifications
You must be signed in to change notification settings - Fork 138
Add legacy class to fix old Form compilation pass #456
Conversation
Please write a changelog directed at end users. Keep in mind that they probably do not care what file or class you changed, but what features you provided / what bugs you fixed. Try to answer the question "What benefit do I get from upgrading?" |
@@ -40,17 +41,19 @@ public function process(ContainerBuilder $container) | |||
} | |||
|
|||
// get factories | |||
$original = $container->getDefinition('form.extension'); | |||
parent::process($container); | |||
if (version_compare(Kernel::VERSION, '2.8', '<')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used version_compare Kernel::VERSION
because:
- it's the first approach inside CompilerPass that I've seen in other CoreBundle files.
- this service is mainly used in the
SonataListFormMappingCommand
that throughisEnabled
checks the symfony version and not the presence of methods...
I think that better rewrite can be made further considering BC behavior from a global perspective...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the first approach inside CompilerPass that I've seen in other CoreBundle files.
Mistakes have been made I'm afraid...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem :-) this is my first commit and I'm worrying about standard etc. that I've already messed.
thanks for your patience!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) please read my last comment though, I think it's the most important: #456 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, we no longer support symfony versions < 2.8 🤔
edit: @greg0ire You mentioned it on other comments, I will read the full discussion before commenting 😄
@@ -82,7 +82,7 @@ public function load(array $configs, ContainerBuilder $container) | |||
$this->registerFlashTypes($container, $config); | |||
$container->setParameter('sonata.core.form_type', $config['form_type']); | |||
|
|||
$this->configureFormFactory($container, $config); | |||
// $this->configureFormFactory($container, $config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove commented code
Please format your commit message according to our rules :
Bad example :
Good example:
More details in CONTRIBUTING.md |
Can you explain what this does, and how you changed it? If I had to take a guess, I'd say you are disabling form mapping for all versions greater than 2.8 (or is it lower?) However, we do not support versions lower than 2.8 (look at composer.json), so these conditions are useless, right? |
The hypothesis about my changes is to restrict the correct behavior only to certain sym version. i.e., considering the "client" class To accomplish this I can fix my PR with `version_compare(Kernel::VERSION, '3, '!='), what do you think about? |
What do you mean by "sym"? |
Oh it's sf, ok |
I'm unsure if the limit should be 3.0 or 3.4, and also, I'm unsure what this means for versions that will not have the code inside the "if". Does it mean people will no longer be able to use |
I re read the error message and see that this is about extending another |
Regarding FormPass, actually there are two implementation, the old one is The problem is that (1) raise deprecation warning. But if I try to remove build fail... |
A solution might be to have 2 passes too, and use the right one depending on the existence of |
Hi @greg0ire Before to proceed with a PR, whats will be the name of the new compile pass class? |
I'd rather you keep the old name and rename the old compiler pass to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog needs an update.
SonataCoreBundle.php
Outdated
} | ||
else { | ||
$container->addCompilerPass(new Compiler\LegacyFormFactoryCompilerPass()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make StyleCi angry, please use PSR-2. Also, you could use a ternary inside addCompilerPass
instead.
This should help fixing StyleCi:
Hoping origin is the main repo here. |
Fetching origin
Current branch 3.x is up to date.
Everything up-to-date |
|
origin https://github.com/nidble/SonataCoreBundle.git (fetch) |
and then try again previous steps |
Legacy FormFactoryCompilerPass raise deprecation warnings because it extends deprecated FormPass. Fixes sonata-project/SonataAdminBundle#4700
StyleCI is green, good job :) |
Travis is failing though, please fix it. |
No response... I'm working on this myself now. |
Ok so here is my understanding of the situation: the sonata core compiler pass listens to the symfony compiler pass, copies the names of all forms and gives it to https://github.com/sonata-project/SonataCoreBundle/blob/3.x/Form/Extension/DependencyInjectionExtension.php#L20-L23 , which allows to use forms "like before". This will probably not work in Symfony 4, and we should stop supporting it. So here what I think should be done:
|
Looks like that setting already exists: https://github.com/sonata-project/SonataCoreBundle/blob/3.x/DependencyInjection/Configuration.php#L45 |
@greg0ire But now, what did you think that default configuration would be |
If you want this make this work, you should find a way to get the array of form type names / form type extensions from the new
That would be a huge BC break, so definitely not. We should disable this feature if the user uses Symfony 4, BTW. |
See my tweet for how to get rid of the the deprecation warning: https://twitter.com/greg0ire/status/927256894724608000 |
Also see #462 |
Make the appropriate changes to this PR, imho involve in two main point:
But doing this, for a service that is used only by |
@nidble you do as you feel, if it's too expensive, don't do it: as I said, people can get rid of the deprecation error the hard (but correct way): sonata_core:
form:
mapping:
enabled: false Well, at least I hope! It would be great if someone actually tried this on their application and reported back 😅 I don't understand the
If you want this to get merged, this service should be able to get all existing form types and extensions, as it does with the legacy version. |
Sure, previously with sf !== 3, I refered at the condition inside Providing new version that works in all circumstances is not useful if that command only works for before condition https://github.com/sonata-project/SonataCoreBundle/blob/3.x/src/Command/SonataListFormMappingCommand.php#L32 |
Ok, let's close this then? |
Could you please rebase your PR and fix merge conflicts? |
I am targeting this branch, because this does not break BC.
Closes sonata-project/SonataAdminBundle#4700
Changelog
Subject
Introduced legacy class to mantain compatibility with old sf versions and to provide a solution against deprecation warnings raised because old
FormFactoryCompilerPass
extends deprecatedFormPass
.After this change if the new
FormPass
class is available, lt will be correctly extended byFormFactoryCompilerPass
whileLegacyFormFactoryCompilerPass
still will mantain BC.