/** * {@inheritdoc} */ public function createBuilderForProperty($class, $property, $data = null, array $options = array()) { if (null === ($guesser = $this->registry->getTypeGuesser())) { return $this->createNamedBuilder($property, 'text', $data, $options); } $typeGuess = $guesser->guessType($class, $property); $maxLengthGuess = $guesser->guessMaxLength($class, $property); $requiredGuess = $guesser->guessRequired($class, $property); $patternGuess = $guesser->guessPattern($class, $property); $type = $typeGuess ? $typeGuess->getType() : 'text'; $maxLength = $maxLengthGuess ? $maxLengthGuess->getValue() : null; $pattern = $patternGuess ? $patternGuess->getValue() : null; if (null !== $pattern) { $options = array_merge(array('attr' => array('pattern' => $pattern)), $options); } if (null !== $maxLength) { $options = array_merge(array('attr' => array('maxlength' => $maxLength)), $options); } if ($requiredGuess) { $options = array_merge(array('required' => $requiredGuess->getValue()), $options); } // user options may override guessed options if ($typeGuess) { $options = array_merge($typeGuess->getOptions(), $options); } return $this->createNamedBuilder($property, $type, $data, $options); }
/** * {@inheritdoc} */ public function createBuilderForProperty($class, $property, $data = null, array $options = array(), FormBuilderInterface $parent = null) { $guesser = $this->registry->getTypeGuesser(); $typeGuess = $guesser->guessType($class, $property); $maxLengthGuess = $guesser->guessMaxLength($class, $property); // Keep $minLengthGuess for BC until Symfony 2.3 $minLengthGuess = $guesser->guessMinLength($class, $property); $requiredGuess = $guesser->guessRequired($class, $property); $patternGuess = $guesser->guessPattern($class, $property); $type = $typeGuess ? $typeGuess->getType() : 'text'; $maxLength = $maxLengthGuess ? $maxLengthGuess->getValue() : null; $minLength = $minLengthGuess ? $minLengthGuess->getValue() : null; $pattern = $patternGuess ? $patternGuess->getValue() : null; // overrides $minLength, if set if (null !== $pattern) { $options = array_merge(array('pattern' => $pattern), $options); } if (null !== $maxLength) { $options = array_merge(array('max_length' => $maxLength), $options); } if (null !== $minLength && $minLength > 0) { $options = array_merge(array('pattern' => '.{' . $minLength . ',' . $maxLength . '}'), $options); } if ($requiredGuess) { $options = array_merge(array('required' => $requiredGuess->getValue()), $options); } // user options may override guessed options if ($typeGuess) { $options = array_merge($typeGuess->getOptions(), $options); } return $this->createNamedBuilder($property, $type, $data, $options, $parent); }