Skip to content

[TwigComponent] Allow to pass stringable object as non mapped component attribute #319

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

Merged
merged 1 commit into from
May 6, 2022

Conversation

norkunas
Copy link
Contributor

@norkunas norkunas commented May 6, 2022

Q A
Bug fix? no
New feature? yes
Tickets N/A
License MIT

Sometimes we have some value objects that are meant to be provided as stimulus controller values and when using {{ component('..', { 'data-item-id-param': objectUuid }) }} it throws an exception that attribute must be scalar.

Now it will allow to accept these objects.

cc @kbond

@norkunas norkunas force-pushed the stringable-objects branch from 597bd48 to 36fcec0 Compare May 6, 2022 03:59
Copy link
Member

@kbond kbond left a comment

Choose a reason for hiding this comment

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

One small thing but looks good to me.

…nt attribute

Sometimes we have some value objects that are meant to be provided as stimulus controller values and when using ``{{ component('..', { 'data-item-id-param': objectUuid }) }}` it throws an exception that attribute must be scalar.

Now it will allow to accept these objects.
@norkunas norkunas force-pushed the stringable-objects branch from 36fcec0 to c1194db Compare May 6, 2022 12:31
@@ -71,6 +71,10 @@ public function create(string $name, array $data = []): MountedComponent

// ensure remaining data is scalar
foreach ($data as $key => $value) {
if ($value instanceof \Stringable) {
Copy link
Member

Choose a reason for hiding this comment

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

Funny timing - we JUST did this with stimulus_controller() also. There, we went further and checked for __toString(): https://github.com/symfony/webpack-encore-bundle/pull/171/files#diff-aac7ca1aa215ab99c76587c963238c082fb42b7a4315344002b7df3046306b8fR64

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe we need to check for the method because this lib is PHP 8+.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

@weaverryan
Copy link
Member

Thanks Tomas!

@weaverryan weaverryan merged commit e4ab138 into symfony:2.x May 6, 2022
@norkunas norkunas deleted the stringable-objects branch May 6, 2022 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants