Skip to content

Commit

Permalink
Merge pull request #2778 from laboro/fix/AER-38_1_12
Browse files Browse the repository at this point in the history
AER-38: Collection form type inconsistency
  • Loading branch information
ignat-s authored Sep 8, 2016
2 parents 59f5cae + 9159b0e commit e19c991
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function preSubmit(FormEvent $event)
$items = $notEmptyItems;

// Set first non empty item for new item as primary
if ($items && !$hasPrimary && $this->isParentFormDataNew($event->getForm()) || count($items) == 1) {
if ($items && !$hasPrimary && count($items) == 1) {
$items[current(array_keys($items))]['primary'] = true;
}

Expand Down Expand Up @@ -104,22 +104,6 @@ protected function hasPrimaryBehaviour(FormEvent $event)
return true;
}

protected function isParentFormDataNew(FormInterface $form)
{
$result = false;
$parent = $form->getParent();
if ($parent) {
$data = $parent->getData();
if (is_object($data)) {
if (method_exists($data, 'getId')) {
$result = !$data->getId();
}
}
}
return $result;

}

/**
* Check if array is empty
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ public function testPreSubmitWithIgnorePrimaryBehaviour()
*
* @param array $data
* @param array $expected
* @param bool $checkIsNew
* @param mixed $parentDataId
*/
public function testPreSubmit(array $data, array $expected, $checkIsNew = false, $parentDataId = null)
public function testPreSubmit(array $data, array $expected)
{
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$formConfig = $this->getMock('Symfony\Component\Form\FormConfigInterface');
Expand All @@ -140,19 +138,6 @@ public function testPreSubmit(array $data, array $expected, $checkIsNew = false,
->with('handle_primary')
->will($this->returnValue(true));

if ($checkIsNew) {
$parentForm = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$parentFormData = $this->getMock('SomeClass', array('getId'));

$form->expects($this->once())->method('getParent')
->will($this->returnValue($parentForm));

$parentForm->expects($this->once())->method('getData')
->will($this->returnValue($parentFormData));

$parentFormData->expects($this->once())->method('getId')
->will($this->returnValue($parentDataId));
}

$event = $this->createEvent($data, $form);
$this->subscriber->preSubmit($event);
Expand All @@ -165,20 +150,14 @@ public function preSubmitDataProvider()
'set_primary_for_new_data' => array(
'data' => array(array('k' => 'v')),
'expected' => array(array('k' => 'v', 'primary' => true)),
'check_is_new' => true,
'parent_data_id' => null
),
'set_primary_for_one_item' => array(
'data' => array(array('k' => 'v')),
'expected' => array(array('k' => 'v', 'primary' => true)),
'check_is_new' => true,
'parent_data_id' => 1
),
'not_set_primary_for_not_new_data' => array(
'not_set_primary_for_two_items' => array(
'data' => array(array('k' => 'v'), array('k2' => 'v2')),
'expected' => array(array('k' => 'v'), array('k2' => 'v2')),
'check_is_new' => true,
'parent_data_id' => 1
),
'primary_is_already_set' => array(
'data' => array(array('primary' => true), array(array('k' => 'v'))),
Expand Down

0 comments on commit e19c991

Please sign in to comment.