-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form][FrameworkBundle][Bridge] Add a DateInterval form type #16809
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
Conversation
For the upcoming hack day and if you find the time to review this for any issues I should fix, a short notice about that would be nice. |
@@ -73,6 +73,9 @@ | |||
<service id="form.type.datetime" class="Symfony\Component\Form\Extension\Core\Type\DateTimeType"> | |||
<tag name="form.type" /> | |||
</service> | |||
<service id="form.type.dateinterval" class="Symfony\Component\Form\Extension\Core\Type\DateIntervalType"> | |||
<tag name="form.type" alias="dateinterval" /> |
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 alias
attribute is now not needed anymore.
95037ca
to
3586785
Compare
Type alias removed and rebased. @xabbuh Sorry for being late... |
👍 |
@@ -73,6 +73,9 @@ | |||
<service id="form.type.datetime" class="Symfony\Component\Form\Extension\Core\Type\DateTimeType"> | |||
<tag name="form.type" /> | |||
</service> | |||
<service id="form.type.dateinterval" class="Symfony\Component\Form\Extension\Core\Type\DateIntervalType"> |
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.
A service for this type is not needed as it has no dependency, we just use FQCN since 2.8. Btw almost all the others have been deprecated in 3.1.
Apart some very minor comments, this PR looks awesome! |
3586785
to
77eff03
Compare
@HeahDude Thanks for your comments. Some of these stem from the fact that this PR was originally based on 2.7. I have updated it accordingly for 3.1+ now. The in-linings would break the soft limit, so I left them out. |
Can you inline even if it breaks the soft limit? We are not following any limits for line length. |
77eff03
to
39ac6de
Compare
@fabpot OK, done :) |
private $fields; | ||
|
||
/** | ||
* Constructor. |
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.
should be removed
@xabbuh I did this in sync with the existing classes, i.e. |
@MisatoTremor Let's do the change for this one for now. |
39ac6de
to
2f8f79d
Compare
@fabpot Done :) |
throw new TransformationFailedException(sprintf('The fields "%s" should not be empty', implode('", "', $emptyFields))); | ||
} | ||
if (isset($value['invert']) && !is_bool($value['invert'])) { | ||
throw new UnexpectedTypeException($value['invert'], 'boolean'); |
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 resulting error message won't help the end user as 'invert' won't be anywhere, right?
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 don't quite understand what you mean with "won't be anywhere".
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 error message is going to be Expected argument of type "boolean", xxx" given
. I don't think there will be anything in the context mentioning that the error comes from the invert
value and not the whole value for the form.
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.
You are right, I oversaw this when applying HeahDudes comments. Fixed
2f8f79d
to
43ad054
Compare
Also add dateinterval widget to twig templates.
43ad054
to
f7669be
Compare
Thank you @MisatoTremor. |
…m type (MisatoTremor) This PR was merged into the 3.2-dev branch. Discussion ---------- [Form][FrameworkBundle][Bridge] Add a DateInterval form type | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13389 | License | MIT | Doc PR | symfony/symfony-docs#4817 Replaces #15030 Commits ------- f7669be [Form] Add a DateInterval form type Also add dateinterval widget to twig templates.
public function __construct(array $fields = null, $pad = false) | ||
{ | ||
if (null === $fields) { | ||
$fields = array('years', 'months', 'days', 'hours', 'minutes', 'seconds', 'invert'); |
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 would use an associative array here instead of plain array (because you often use array_flip
, and isset($array[$key])
is faster than in_array($key, $array)
)
Thanks all for your help improving this and thanks for merging. |
$fields = array('years', 'months', 'days', 'hours', 'minutes', 'seconds', 'invert'); | ||
} | ||
$this->fields = $fields; | ||
$this->pad = (bool) $pad; |
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.
@MisatoTremor We're missing the actual pad
property at the top of this class
This PR was merged into the 3.2-dev branch. Discussion ---------- [Form][#16809] add missing pad property | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16809 (comment) | License | MIT | Doc PR | Commits ------- 647e6ba [#16809] add missing pad property
Replaces #15030