10000 More intuitive matching of bundle directory lookups for Doctrine extensions by jmikola · Pull Request #36 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

More intuitive matching of bundle directory lookups for Doctrine extensions #36

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 9 commits into from
50 changes: 19 additions & 31 deletions src/Symfony/Component/Form/CollectionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
class CollectionField extends FieldGroup
{
CONST PLACEHOLDER_KEY = '$$key$$';

/**
* The prototype for the inner fields
* @var FieldInterface
Expand All @@ -42,6 +40,13 @@ public function __construct(FieldInterface $innerField, array $options = array()
protected function configure()
{
$this->addOption('modifiable', false);

if ($this->getOption('modifiable')) {
$field = $this->newField('$$key$$', null);
// TESTME
$field->setRequired(false);
$this->add($field);
}
}

public function setData($collection)
Expand All @@ -50,13 +55,13 @@ public function setData($collection)
throw new UnexpectedTypeException('The data must be an array');
}

foreach ($this as $name => $field)
{
$this->remove($name);
foreach ($this as $name => $field) {
if (!$this->getOption('modifiable') || $name != '$$key$$') {
$this->remove($name);
}
}

foreach ($collection as $name => $value)
{
foreach ($collection as $name => $value) {
$this->add($this->newField($name, $name));
}

Expand All @@ -69,25 +74,15 @@ public function bind($taintedData)
$taintedData = array();
}

if ($this->getOption('modifiable'))
{
unset($taintedData[self::PLACEHOLDER_KEY]);
parent::setData(null);

foreach ($this as $name => $field)
{
if (!isset($taintedData[$name]))
{
$this->remove($name);
}
foreach ($this as $name => $field) {
if (!isset($taintedData[$name]) && $this->getOption('modifiable') && $name != '$$key$$') {
$this->remove($name);
}
}

foreach ($taintedData as $name => $value)
{
if (!isset($this[$name]))
{
$this->add($this->newField($name, $name));
}
foreach ($taintedData as $name => $value) {
if (!isset($this[$name]) && $this->getOption('modifiable')) {
$this->add($this->newField($name, $name));
}
}

Expand All @@ -101,11 +96,4 @@ protected function newField($key, $propertyPath)
$field->setPropertyPath($propertyPath === null ? null : '['.$propertyPath.']');
return $field;
}

public function getPlaceholderField()
{
$field = $this->newField(self::PLACEHOLDER_KEY, null);
$field->setParent($this);
return $field;
}
}
0