public function reverseTransform($value) { if (!is_array($value)) { throw new TransformationFailedException('Checkbox grid reverse-transformer needs an array as input'); } $result = array(); $accessor = PropertyAccess::createPropertyAccessor(); foreach ($value as $yValue => $row) { if (!is_array($row)) { throw new TransformationFailedException('Checkbox grid reverse-transformer needs a 2D array'); } $yChoiceMatch = $this->yChoiceList->getChoicesForValues(array($yValue)); if (!$yChoiceMatch) { continue; } foreach ($row as $xValue => $checked) { $xChoiceMatch = $this->xChoiceList->getChoicesForValues(array($xValue)); if ($xChoiceMatch && $checked) { if (is_bool($checked)) { if ($this->class === null) { $object = array(); } else { $object = new $this->class(); } } else { $object = $checked; } $accessor->setValue($object, $this->xPath, reset($xChoiceMatch)); $accessor->setValue($object, $this->yPath, reset($yChoiceMatch)); $result[] = $object; } } } return $result; }
function it_builds_attribute_types_prototype_and_passes_it_as_argument(FormBuilder $builder, FormBuilder $fieldBuilder, FormFactoryInterface $formFactory, ChoiceListInterface $choiceList, AttributeInterface $attribute) { $builder->getFormFactory()->willReturn($formFactory); $builder->add('attribute', 'sylius_server_attribute_choice', Argument::any())->willReturn($builder); $builder->addEventSubscriber(Argument::any())->willReturn($builder); $attribute->getType()->willReturn('checkbox')->shouldBeCalled(); $attribute->getConfiguration()->willReturn(array('label' => 'sylius.form.attribute.server_attribute_value.value'))->shouldBeCalled(); $choiceList->getChoices()->willReturn(array($attribute)); $fieldBuilder->getOption('choice_list')->willReturn($choiceList); $builder->get('attribute')->willReturn($fieldBuilder); $builder->create('value', 'checkbox', array('label' => 'sylius.form.attribute.server_attribute_value.value'))->shouldBeCalled()->willReturn($fieldBuilder); $fieldBuilder->getForm()->willReturn('Form for attribute'); $builder->setAttribute('prototypes', array(0 => 'Form for attribute'))->shouldBeCalled(); $this->buildForm($builder, array()); }
/** * {@inheritdoc} * * @deprecated Deprecated since version 2.4, to be removed in 3.0. */ public function getIndicesForValues(array $values) { if (!$this->choiceList) { $this->load(); } return $this->choiceList->getIndicesForValues($values); }
/** * {@inheritdoc} * * @deprecated since version 2.4, to be removed in 3.0. */ public function getIndicesForValues(array $values) { trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED); if (!$this->choiceList) { $this->load(); } return $this->choiceList->getIndicesForValues($values); }
private function initialize() { $this->choices = array(); $this->values = array(); $this->structuredValues = $this->adaptedList->getValues(); $innerChoices = $this->adaptedList->getChoices(); foreach ($innerChoices as $index => $choice) { $value = $this->structuredValues[$index]; $this->values[] = $value; $this->choices[$value] = $choice; } }
public function testGetValuesForChoicesEmpty() { $this->assertSame(array(), $this->list->getValuesForChoices(array())); }
private function handleChoiceListValues(ChoiceListInterface $choiceList) { $choices = array(); foreach (array($choiceList->getPreferredViews(), $choiceList->getRemainingViews()) as $viewList) { $choices = array_merge($choices, $this->handleChoiceViewsHierarchy($viewList)); } return $choices; }
public function testGetValuesForChoices() { $this->adaptedList->expects($this->once())->method('getValuesForChoices')->with(array(1 => 'a', 4 => 'b', 7 => 'c'))->willReturn(array(1 => ':a', 4 => ':b', 7 => ':c')); $this->assertSame(array(1 => ':a', 4 => ':b', 7 => ':c'), $this->list->getValuesForChoices(array(1 => 'a', 4 => 'b', 7 => 'c'))); }