Skip to content

[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

Merged
merged 1 commit into from
Jun 22, 2016

Conversation

MisatoTremor
Copy link
Contributor

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

@MisatoTremor
Copy link
Contributor Author

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" />
Copy link
Member

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.

@MisatoTremor MisatoTremor force-pushed the add_dateinterval_type_3_1 branch from 95037ca to 3586785 Compare March 13, 2016 17:46
@MisatoTremor
Copy link
Contributor Author

Type alias removed and rebased.

@xabbuh Sorry for being late...

@fabpot
Copy link
Member

fabpot commented Jun 16, 2016

👍

@@ -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">
Copy link
Contributor

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.

@HeahDude
Copy link
Contributor

Apart some very minor comments, this PR looks awesome!

@MisatoTremor MisatoTremor force-pushed the add_dateinterval_type_3_1 branch from 3586785 to 77eff03 Compare June 17, 2016 09:23
@MisatoTremor
Copy link
Contributor Author

@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.

@fabpot
Copy link
Member

fabpot commented Jun 17, 2016

Can you inline even if it breaks the soft limit? We are not following any limits for line length.

@MisatoTremor MisatoTremor force-pushed the add_dateinterval_type_3_1 branch from 77eff03 to 39ac6de Compare June 17, 2016 10:15
@MisatoTremor
Copy link
Contributor Author

@fabpot OK, done :)

private $fields;

/**
* Constructor.
Copy link
Member

Choose a reason for hiding this comment

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

should be removed

@MisatoTremor
Copy link
Contributor Author

@xabbuh I did this in sync with the existing classes, i.e. DateTimeToArrayTransformer. Should I really change it only for this one (now)?

@fabpot
Copy link
Member

fabpot commented Jun 21, 2016

@MisatoTremor Let's do the change for this one for now.

@MisatoTremor MisatoTremor force-pushed the add_dateinterval_type_3_1 branch from 39ac6de to 2f8f79d Compare June 21, 2016 14:40
@MisatoTremor
Copy link
Contributor Author

@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');
Copy link
Member

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?

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 quite understand what you mean with "won't be anywhere".

Copy link
Member

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.

Copy link
Contributor Author

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

@MisatoTremor MisatoTremor force-pushed the add_dateinterval_type_3_1 branch from 2f8f79d to 43ad054 Compare June 22, 2016 11:46
Also add dateinterval widget to twig templates.
@MisatoTremor MisatoTremor force-pushed the add_dateinterval_type_3_1 branch from 43ad054 to f7669be Compare June 22, 2016 11:52
@fabpot
Copy link
Member

fabpot commented Jun 22, 2016

Thank you @MisatoTremor.

@fabpot fabpot merged commit f7669be into symfony:master Jun 22, 2016
fabpot added a commit that referenced this pull request Jun 22, 2016
…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');
Copy link
Contributor

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))

@MisatoTremor
Copy link
Contributor Author

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;
Copy link
Member

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

xabbuh added a commit to xabbuh/symfony that referenced this pull request Jul 10, 2016
fabpot added a commit that referenced this pull request Jul 11, 2016
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
@fabpot fabpot mentioned this pull request Oct 27, 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.

8 participants