Skip to content

[Form] Refactor guessing of form options and added min and max guessing #9759

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

Closed
wants to merge 20 commits into from

Conversation

stefanosala
Copy link

Q A
Bug fix? no
New feature? yes
BC breaks? FormTypeGuesserInterface change
Deprecations? max_length and pattern form options
Tests pass? yes
Fixed tickets #6732
License MIT

We worked on issue #6732 and we added automatically min and max attributes to integer type based on Range validator.
It should work also for numeric type, but at the moment it is being rendered as "text" input type. Is there a specific reason beside the comment "type="number" doesn't work with floats"?

We are now working on implementing a guess{Max|Min}Value on Doctrine and Propel guesser.

Credits: @dlondero

@stefanosala
Copy link
Author

@bschussek: It can work also for number type, but at the moment it is being rendered as "text" input type. Is there a specific reason beside the comment "type="number" doesn't work with floats"?

'integer',
array(),
Guess::HIGH_CONFIDENCE
)));
Copy link
Contributor

Choose a reason for hiding this comment

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

thought ubot could detect this wrong indentation

Copy link
Author

Choose a reason for hiding this comment

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

Let's wait for him to come and check, I'll prepare a fix.

Copy link
Author

Choose a reason for hiding this comment

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

Apparently he is not so fast, I'll push my fix right now :)

@webmozart
Copy link
Contributor

I don't like the original approach that I chose for the type guessers too much anymore. I think instead of adding more methods to that interface, we should try to simplify it:

public function guessType($class, $property);

public function guessOptions($class, $property, $type);

The first method would be basically the same as now, except that it would return only the type, and not the options. (BC should be kept somehow at this point) The second method would then return the options for a class property, given that type $type was selected.

The difference to the current behavior would be that guessOptions() should always be used, even if a type is manually provided.

Do you want to implement this change?

@stefanosala
Copy link
Author

I definitely agree and I can work on it.

@stefanosala
Copy link
Author

I started working on it from the ValidatorTypeGuesser and the max_length option.
@bschussek can you please check if this is the direction you imagined?

@@ -42,6 +42,24 @@ public function guessType($class, $property)
/**
* {@inheritDoc}
*/
public function guessOptions($class, $property, $type)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should add the type hint ResolvedFormTypeInterface to the $type argument.

@webmozart
Copy link
Contributor

Yes, looks good! :)

@fabpot
Copy link
Member

fabpot commented Dec 31, 2013

@stewe I see that this PR is WIP; will you have time to finish it in the near future?

@stefanosala
Copy link
Author

Yes, I'm working on it. Hope to complete it before the end of the week.

@stefanosala
Copy link
Author

Done. Let's just recap a couple of things:

  • I deprecated the options max_length and pattern and moved them to the attr option;
  • I added the guessing of min and max attributes;

Please review my commits and let me know if I need to adjust or add something and let me know if I need to squash the commits.
Thank you!

@fabpot
Copy link
Member

fabpot commented Jan 4, 2014

@bschussek Can you review this one please?

@@ -122,7 +140,7 @@ public function guessRequired($class, $property)
/**
* {@inheritDoc}
*/
public function guessMaxLength($class, $property)
protected function guessMaxLength($class, $property)
Copy link
Contributor

Choose a reason for hiding this comment

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

why protected? As far as I see, it's not used for inheritance. So it should either be private or public (for BC).
Applies to all of these changes.

@stefanosala
Copy link
Author

Wait, tests are failing, let me fix them.

$this->assertNotNull($value);
$this->assertNull($value->getValue());
$this->assertArrayHasKey('maxlength', $attributes);
$this->assertEquals(null, $attributes['maxlength']->getValue());
Copy link
Contributor

Choose a reason for hiding this comment

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

assertNull() same below.

@stefanosala
Copy link
Author

@stloyd @Tobion thanks for your review.

@@ -120,7 +138,12 @@ public function guessRequired($class, $property)
}

/**
* {@inheritDoc}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you changed to @deprecated you can use @inheritdoc again.

Copy link
Author

Choose a reason for hiding this comment

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

Right, thanks!

@stefanosala
Copy link
Author

Ping?

@webmozart
Copy link
Contributor

Hi @stewe, thank you for the awesome PR! Some feedback:

  • This PR currently contains two different changes: The deprecation of the "max_length" and "pattern" options, and the change of the value guesser. Could you do the option deprecation in a separate PR? This PR will be quite small and quick to review and merge.
  • You added a new method guessAttributes(), but I suggested guessOptions() with a slightly different signature above. Could you change this? guessOptions() should then return an array with the "attr" option set.

@stefanosala
Copy link
Author

Hi @bschussek, thanks for you reply.

  • Yes, I will.
  • I'm sorry, I didn't write you back my consideration.

If guessOptions($class, $property, ResolvedFormTypeInterface $type) is the signature of the method, how can I:

  • get a ResolvedFormTypeInterface in FormFactory?
  • check that the ResolvedFormTypeInterface supports a particular attribute?

fabpot added a commit that referenced this pull request Mar 26, 2014
…anosala)

This PR was squashed before being merged into the 2.5-dev branch (closes #10001).

Discussion
----------

[Form] Deprecated max_length and pattern options

Split of issue #9759

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | `max_length` and `pattern` in form options
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#3461

Commits
-------

52c07c7 Deprecated max_length and pattern options
@fabpot
Copy link
Member

fabpot commented Mar 26, 2014

#10001 has been merged now, so this PR should probably be rebased.

@sstok
Copy link
Contributor

sstok commented Jul 27, 2014

@stefanosala ping

@stefanosala
Copy link
Author

@sstok I could rebase this, but honestly I have no idea how to go on on this.

@stefanosala
Copy link
Author

I will close this in favour of #7868

@stefanosala stefanosala deleted the issue-6732 branch September 25, 2014 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants