コード例 #1
0
 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;
 }
コード例 #2
0
 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());
 }
コード例 #3
0
 /**
  * {@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);
 }
コード例 #4
0
ファイル: LazyChoiceList.php プロジェクト: vadim2404/symfony
 /**
  * {@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);
 }
コード例 #5
0
 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;
     }
 }
コード例 #6
0
 public function testGetValuesForChoicesEmpty()
 {
     $this->assertSame(array(), $this->list->getValuesForChoices(array()));
 }
コード例 #7
0
 private function handleChoiceListValues(ChoiceListInterface $choiceList)
 {
     $choices = array();
     foreach (array($choiceList->getPreferredViews(), $choiceList->getRemainingViews()) as $viewList) {
         $choices = array_merge($choices, $this->handleChoiceViewsHierarchy($viewList));
     }
     return $choices;
 }
コード例 #8
0
 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')));
 }