/** * @param \Sonata\AdminBundle\Admin\FieldDescriptionCollection $list * @param null $type * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription * @param \Sonata\AdminBundle\Admin\AdminInterface $admin */ public function addField(FieldDescriptionCollection $list, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin) { if ($type == null) { $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager()); $fieldDescription->setType($guessType->getType()); } else { $fieldDescription->setType($type); } $this->fixFieldDescription($admin, $fieldDescription); $admin->addShowFieldDescription($fieldDescription->getName(), $fieldDescription); $list->add($fieldDescription); }
/** * {@inheritDoc} */ public function addField(FieldDescriptionCollection $list, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin) { if ($type == null) { $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager()); $fieldDescription->setType($guessType->getType()); } else { $fieldDescription->setType($type); } $this->fixFieldDescription($admin, $fieldDescription); $admin->addShowFieldDescription($fieldDescription->getName(), $fieldDescription); switch ($fieldDescription->getMappingType()) { case ClassMetadata::MANY_TO_ONE: case ClassMetadata::MANY_TO_MANY: return; default: $list->add($fieldDescription); } }
public function testReorderListWithBatchField() { $collection = new FieldDescriptionCollection(); $fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface'); $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('title')); $collection->add($fieldDescription); $fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface'); $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('position')); $collection->add($fieldDescription); $fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface'); $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('batch')); $collection->add($fieldDescription); $newOrder = array('position', 'title'); $collection->reorder($newOrder); array_unshift($newOrder, 'batch'); $actualElements = array_keys($collection->getElements()); $this->assertSame($newOrder, $actualElements, 'the order is wrong'); }
public function testReorder() { $fieldDescription1 = $this->getFieldDescriptionMock('fooName1', 'fooLabel1'); $fieldDescription2 = $this->getFieldDescriptionMock('fooName2', 'fooLabel2'); $fieldDescription3 = $this->getFieldDescriptionMock('fooName3', 'fooLabel3'); $fieldDescription4 = $this->getFieldDescriptionMock('fooName4', 'fooLabel4'); $this->listMapper->add($fieldDescription1); $this->listMapper->add($fieldDescription2); $this->listMapper->add($fieldDescription3); $this->listMapper->add($fieldDescription4); $this->assertEquals(array('fooName1' => $fieldDescription1, 'fooName2' => $fieldDescription2, 'fooName3' => $fieldDescription3, 'fooName4' => $fieldDescription4), $this->fieldDescriptionCollection->getElements()); $this->listMapper->reorder(array('fooName3', 'fooName2', 'fooName1', 'fooName4')); // print_r is used to compare order of items in associative arrays $this->assertEquals(print_r(array('fooName3' => $fieldDescription3, 'fooName2' => $fieldDescription2, 'fooName1' => $fieldDescription1, 'fooName4' => $fieldDescription4), true), print_r($this->fieldDescriptionCollection->getElements(), true)); }
/** * {@inheritdoc} */ public function addField(FieldDescriptionCollection $list, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin) { $this->buildField($type, $fieldDescription, $admin); $admin->addListFieldDescription($fieldDescription->getName(), $fieldDescription); $list->add($fieldDescription); }
/** * {@inheritdoc} */ public function reorder(array $keys) { $this->list->reorder($keys); return $this; }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage Element "foo" does not exist. */ public function testNonExistentField() { $collection = new FieldDescriptionCollection(); $collection->get('foo'); }