Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] simplify the form type extension registration#24530

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromxabbuh:issue-22833
Oct 10, 2018

Conversation

@xabbuh
Copy link
Member

@xabbuhxabbuh commentedOct 12, 2017
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#22833,#27906
LicenseMIT
Doc PR

yceruto, Tobion, and zmitic reacted with thumbs up emojijvasseur and dxops reacted with confused emoji
@xabbuh
Copy link
MemberAuthor

changelog and upgrade files need to be updated

"symfony/asset":"<3.4",
"symfony/console":"<3.4",
"symfony/form":"<3.4",
"symfony/form":"<4.0",
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

must be changed to<4.1 when the4.0 branch is created

@vudaltsov
Copy link
Contributor

Great!

By the way, does it make sense to be able to extend multiple types with one extension?
Can it be implemented?

@xabbuhxabbuhforce-pushed theissue-22833 branch 2 times, most recently fromb26fc2d toaecdc5fCompareOctober 12, 2017 11:55
"symfony/polyfill-intl-icu":"~1.0",
"symfony/security":"~3.4|~4.0",
"symfony/form":"~3.4|~4.0",
"symfony/form":"~4.0",
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

would need to be changed to~4.1

@xabbuh
Copy link
MemberAuthor

@vudaltsov Implementing it wouldn't be hard. But IMO it's not really worth it.

@xabbuh
Copy link
MemberAuthor

We could also think about deprecating theFormTypeExtensionInterface::getExtendedType() method (providing an implementation inAbstractTypeExtension for a smooth upgrade path) as it will be pretty useless in Symfony 5.

yceruto, apfelbox, Tynael, and zmitic reacted with thumbs up emoji

----

* Support for the`extended_type` attribute inside the`FormPass` is deprecated and will be dropped in Symfony 5.0.
Implement the`public static function extends(): string` method in your form type extension class instead.
Copy link
Member

Choose a reason for hiding this comment

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

extendsType()? Same inUPGRADE-5.0.md andsrc/Symfony/Component/Form/CHANGELOG.md

Implement the`public static function extends(): string` method in your form type extension class instead.

* Not implementing the`extendsType()` method when implementing the`FormTypeExtensionInterface` is deprecated. The
method will be added to the`FormTypeExtensionInterface` in Symfony 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.

in Symfony 5.0? Same insrc/Symfony/Component/Form/CHANGELOG.md

*/
publicfunctiongetExtendedType()
{
return'Symfony\Component\Form\Extension\Core\Type\FormType';
Copy link
Member

Choose a reason for hiding this comment

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

What do you think aboutreturn self::extendsType(); to make clearer the migration path?

ogizanagi reacted with thumbs up emoji

$this->fail();
}catch (InvalidArgumentException$e) {
$this->assertSame('"form.type_extension" tagged services must have the extended type configured using the extended_type/extended-type attribute, none was configured for the "my.type_extension" service.',$e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

why not keeping@expectedException and@expectedExceptionMessage ?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@expectedDeprecation would not be evaluated then


if (method_exists($this,'extendsType')) {
return$this::extendsType();
}
Copy link
Member

Choose a reason for hiding this comment

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

you must throw an exception here, telling to implement the other method or to override this one, because returningnull is not allowed.

*
* @return string The name of the type being extended
*
* @deprecated since version 4.1, implement extendsType() instead
Copy link
Contributor

Choose a reason for hiding this comment

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

we often add the to-be-added method as commented code in the interface

Copy link
Contributor

Choose a reason for hiding this comment

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

using@method seems like a new approach. works both I guess

@xabbuh
Copy link
MemberAuthor

Status: Needs Review

@Tobion
Copy link
Contributor

This needs a rebase. Also I think we don't necessarily need to deprecateextended_type tag attribute. Just making it optional and using the staticextendsType method by default should be enough. This covers 99% of the cases. If someone uses the same class with different services instances for different extensions, they can still use theextended_type attribute. This would then be similar to thecommand attribute of theconsole.command tag.

Also this change allows to autoconfigure form type extensions. So I guess this should be added as well.

yceruto and sstok reacted with thumbs up emoji

@xabbuhxabbuh added the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelMar 12, 2018
foreach ($this->typeExtensionServices[$name]as$serviceId =>$extension) {
$extensions[] =$extension;

if (method_exists($extension,'getExtendedTypes')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This validation prevents to use different instances of the same class to be used for different extensions. So it prevents the only advantage ofextended_type attribute that I mentioned in#24530 (comment) as people will be forced to implement the method in 5.0 when its part of the interface. So they need to return an empty array and then overwrite it with the service attribute.

IMO we do not need the validation anymore as now both the registration and implementation uses getExtendedTypes. So there should not be a mismatch anymore unless you wire something wrong manually.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

class FooBarTypeExtensionextends AbstractTypeExtension{publicfunction__construct(string$type)    {    }publicstaticfunctiongetExtendedTypes():iterable    {returnarray(            FooType::class,            BarType::class,        );    }}
App\Form\FooBarTypeExtension:arguments:['foo']tags:        -name:form.type_extensionextended_type:FooTypeApp\Form\FooBarTypeExtension:arguments:['bar']tags:        -name:form.type_extensionextended_type:BarType

Do I understand correctly that you have something like this in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. By returning both types from getExtendedTypes, it actually works even with the validation. So I'm fine keeping it like this. But I think it would make more sense to remove the validation as it should not matter what is returned by getExtendedTypes if you set the extended_type attribute (and you might not even know that in advance if you create a dynamic form extension).

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I wonder if we shouldn't rather deprecate theextended_type attribute too instead I could imagine that using it adds more confusion than an implementation wheregetExtendedTypes() is the single source of truth.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it potentially is complicating things for no real use-case. But I also like that it allows to configure extensions dynamically via DI (instead of hardcoding it into a class). As I said in#24530 (comment), its similar to the command attribute of the console.command tag. So it would be consistent to keep it. But I would not object to deprecate it as well.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Let's keep it for now. We can still consider to deprecate it later when we noticed that it adds too much confusion.

// validate result of getExtendedType() to ensure it is consistent with the service definition
if ($extension->getExtendedType() !==$name) {
if (!\in_array($name,$extendedTypes,true)) {
thrownewInvalidArgumentException(sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s".',$serviceId,$name,$extension->getExtendedType()));
Copy link
Contributor

Choose a reason for hiding this comment

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

$extension->getExtendedType() would need to be replaced by$extendedTypes. But as said above, the whole thing could be removed.

{
}

publicfunctiongetExtendedType()
Copy link
Contributor

Choose a reason for hiding this comment

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

WithgetExtendedType deprecated, all the calls that are still done to it need to use the new static method instead when it exists. E.g. in AbstractExtension that yceruto mentioned. And it should also trigger a deprecation message or is this done automatically?

@xabbuh
Copy link
MemberAuthor

@Tobion I added some deprecation triggers at some places where type extensions are registered. This also allowed me to discover some places that still needed to be updated.

Copy link
Contributor

@TobionTobion left a comment

Choose a reason for hiding this comment

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

Good job. I think moving this to a static method makes sense as it allows autowiring and is consistent with similar concepts that need to be known at container comilation like EventSubscriberInterface and MessageHandlerSubscriberInterface.

@fabpot
Copy link
Member

Thank you@xabbuh.

@fabpotfabpot merged commit6a1d4c5 intosymfony:masterOct 10, 2018
fabpot added a commit that referenced this pull requestOct 10, 2018
…xabbuh)This PR was merged into the 4.2-dev branch.Discussion----------[Form] simplify the form type extension registration| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#22833,#27906| License       | MIT| Doc PR        |Commits-------6a1d4c5 simplify the form type extension registration
@xabbuhxabbuh deleted the issue-22833 branchOctober 10, 2018 09:21
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
symfony-splitter pushed a commit to symfony/form that referenced this pull requestMay 29, 2019
…ethod (yceruto)This PR was merged into the 5.0-dev branch.Discussion----------[Form] Remove legacy code related to getExtendedType() method| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Ref:symfony/symfony#24530Commits-------208b729bca Remove legacy code related to getExtendedType() method
nicolas-grekas added a commit that referenced this pull requestMay 29, 2019
…ethod (yceruto)This PR was merged into the 5.0-dev branch.Discussion----------[Form] Remove legacy code related to getExtendedType() method| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Ref:#24530Commits-------208b729 Remove legacy code related to getExtendedType() method
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ycerutoycerutoyceruto left review comments

@chalasrchalasrchalasr left review comments

@stofstofstof requested changes

@fabpotfabpotfabpot approved these changes

+3 more reviewers

@TobionTobionTobion approved these changes

@ogizanagiogizanagiogizanagi approved these changes

@vudaltsovvudaltsovvudaltsov approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

12 participants

@xabbuh@vudaltsov@Tobion@lyrixx@javiereguiluz@fabpot@stof@yceruto@ogizanagi@chalasr@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp