Skip to content

[form] lazy trans post_max_size_message. #19595

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
Sep 6, 2016

Conversation

aitboudad
Copy link
Contributor

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #19256
License MIT
Doc PR ~

}

/**
* This method is public because it needs to be callable from a closure in PHP 5.3.
Copy link
Member

Choose a reason for hiding this comment

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

you can do without it by using a reference in the use of the closure, wouldn't that be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

even better :), thanks

@@ -81,7 +81,7 @@ public function handleRequest(FormInterface $form, $request = null)
$form->submit(null, false);

$form->addError(new FormError(
$form->getConfig()->getOption('post_max_size_message'),
(string) $form->getConfig()->getOption('post_max_size_message'),
Copy link
Member

Choose a reason for hiding this comment

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

could this be a bc break somehow?

Copy link
Contributor Author

@aitboudad aitboudad Aug 13, 2016

Choose a reason for hiding this comment

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

not sure, but it can be treated as a string like the old ones

Copy link
Member

Choose a reason for hiding this comment

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

does it work if you remove the cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just checked and I found that it can lead a bc break (if someone try to serialize this option)

@nicolas-grekas
Copy link
Member

@aitboudad any other idea to fix the linked issue that has no bc break inside?

@@ -55,4 +57,9 @@ public function getExtendedType()
{
return 'form';
}

public function __toString()
Copy link
Member

Choose a reason for hiding this comment

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

-1 for making the TypeExtension itself castable to string as the error message. It looks really weird to me.

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 don't like either :), but I was looking for a solution to avoid bc break

@aitboudad
Copy link
Contributor Author

Replace post_max_size_message with a new option upload_max_size_message that return a callable type is an alternative solution, what do you think ?

@nicolas-grekas
Copy link
Member

@aitboudad let's try :)

@aitboudad aitboudad force-pushed the form-upload-trans branch 3 times, most recently from 6f52062 to 7797a16 Compare August 24, 2016 12:05
@aitboudad
Copy link
Contributor Author

done

@@ -207,8 +213,10 @@ public function configureOptions(OptionsResolver $resolver)
'action' => '',
'attr' => $defaultAttr,
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
'upload_max_size_message' => $uploadMaxSizeMessage,
Copy link
Contributor

Choose a reason for hiding this comment

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

You could add // internal at the end of the line, and/or maybe add a comment somewhere explaining why you define it as a callable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just added a small description, can you look up ?

@HeahDude
Copy link
Contributor

Wow, great! Thanks for that fix!

@@ -146,6 +146,14 @@ public function configureOptions(OptionsResolver $resolver)
};
};

// Derive "upload_max_size_message" closure from "post_max_size_message" option,
// to allow override or translate the message only when it's needed and not during the resolve `options`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there are typo: overriding and translating.

What about something like:

// Wrap "post_max_size_message" in a closure to translate it lazily
 $uploadMaxSizeMessage ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good one, thanks!

@HeahDude
Copy link
Contributor

HeahDude commented Sep 6, 2016

This one is very tricky :)

👍

Status: reviewed

@fabpot
Copy link
Member

fabpot commented Sep 6, 2016

Thank you @aitboudad.

@fabpot fabpot merged commit c03164e into symfony:2.7 Sep 6, 2016
fabpot added a commit that referenced this pull request Sep 6, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

[form] lazy trans `post_max_size_message`.

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19256
| License       | MIT
| Doc PR        | ~

Commits
-------

c03164e [form] lazy trans `post_max_size_message`.
@aitboudad aitboudad deleted the form-upload-trans branch September 6, 2016 16:14
This was referenced Sep 7, 2016
@fabpot fabpot mentioned this pull request Oct 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants