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
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Deprecated max_length and pattern options
  • Loading branch information
Stefano Sala committed Mar 31, 2014
commit e85639a1e74ed4b02f5d09ecb3738ffd9c00f18e
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ public function requiredProvider()

// Simple field, not nullable
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->any())->method('hasField')->with('field')->will($this->returnValue(true));
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(true));
$classMetadata->expects($this->once())->method('isNullable')->with('field')->will($this->returnValue(false));

$return[] = array($classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE));

// Simple field, nullable
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->any())->method('hasField')->with('field')->will($this->returnValue(true));
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(true));
$classMetadata->expects($this->once())->method('isNullable')->with('field')->will($this->returnValue(true));

$return[] = array($classMetadata, new ValueGuess(false, Guess::MEDIUM_CONFIDENCE));

// One-to-one, nullable (by default)
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->any())->method('hasField')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));

$mapping = array('joinColumns' => array(array()));
Expand All @@ -56,7 +56,7 @@ public function requiredProvider()

// One-to-one, nullable (explicit)
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->any())->method('hasField')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));

$mapping = array('joinColumns' => array(array('nullable'=>true)));
Expand All @@ -66,7 +66,7 @@ public function requiredProvider()

// One-to-one, not nullable
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->any())->method('hasField')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));

$mapping = array('joinColumns' => array(array('nullable'=>false)));
Expand All @@ -76,7 +76,7 @@ public function requiredProvider()

// One-to-many, no clue
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata->expects($this->any())->method('hasField')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(false));
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(false));

$return[] = array($classMetadata, null);
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/FormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'empty_data' => $emptyData,
'trim' => true,
'required' => true,
'max_length' => null,
'pattern' => null,
'read_only' => false,
'property_path' => null,
'mapped' => true,
Expand Down
17 changes: 10 additions & 7 deletions src/Symfony/Component/Form/FormTypeGuesserChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ public function guessAttributes($class, $property)
{
$attributes = array();

// Cleanup attributes if I get the same attribute from different guessers.
foreach ($this->guessers as $guesser) {
$guessedAttributes = $guesser->guessAttributes($class, $property);

if (is_array($guessedAttributes)) {
foreach ($guessedAttributes as $key => $value) {
if (isset($attributes[$key])) {
$attributes[$key] = Guess::getBestGuess(array($attributes[$key], $value));
} else {
$attributes[$key] = $value;
}
if (false === is_array($guessedAttributes)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just if (!is_array($guessedAttributes)) { is enough.

continue;
}

foreach ($guessedAttributes as $key => $value) {
if (isset($attributes[$key])) {
$attributes[$key] = Guess::getBestGuess(array($attributes[$key], $value));
} else {
$attributes[$key] = $value;
}
}
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy