/**
  * Returns a new FieldDescription.
  *
  * The description is filled with the information retrieved from
  * * the respective Peer-class and
  * * the TableMap of the model class.
  *
  * @param string $class   The FQCN of the model.
  * @param string $name    The column name of the model (should be given as a phpName).
  * @param array  $options A list of options to be passed to the new FielDescription.
  *
  * @return FieldDescription
  */
 public function getNewFieldDescriptionInstance($class, $name, array $options = array())
 {
     if (!is_string($name)) {
         throw new \RunTimeException('The name argument must be a string');
     }
     $fieldDescription = new FieldDescription();
     $fieldDescription->setName($name);
     $fieldDescription->setOptions($options);
     $fieldDescription->setParentAssociationMappings($this->getParentAssociationMappings($class, $name));
     if (!($table = $this->getTable($class))) {
         return $fieldDescription;
         // TODO should we throw a logic exception here ?
     }
     foreach ($table->getRelations() as $relation) {
         if ($relation->getType() === \RelationMap::MANY_TO_ONE) {
             if (strtolower($name) === strtolower($relation->getName())) {
                 $fieldDescription->setAssociationMapping(array('targetEntity' => $relation->getForeignTable()->getClassName(), 'type' => $relation->getType()));
             }
         } elseif ($relation->getType() === \RelationMap::ONE_TO_MANY) {
             if (strtolower($name) === strtolower($relation->getPluralName())) {
                 $fieldDescription->setAssociationMapping(array('targetEntity' => $relation->getForeignTable()->getClassName(), 'type' => $relation->getType()));
             }
         } elseif ($relation->getType() === \RelationMap::MANY_TO_MANY) {
             if (strtolower($name) === strtolower($relation->getPluralName())) {
                 $fieldDescription->setAssociationMapping(array('targetEntity' => $relation->getLocalTable()->getClassName(), 'type' => $relation->getType()));
             }
         }
     }
     if ($column = $this->getColumn($class, $name)) {
         $fieldDescription->setType($column->getType());
         $fieldDescription->setFieldMapping(array('id' => $column->isPrimaryKey(), 'fieldName' => $column->getPhpName(), 'type' => $column->getType()));
     }
     return $fieldDescription;
 }
 public function testActionLinksWithDefaultConfig()
 {
     $field = new FieldDescription();
     $field->setName('_action');
     $field->setOption('actions', array('show' => array(), 'edit' => array()));
     $builder = new ListBuilder($this->typeGuesser);
     $builder->addField($this->list, 'actions', $field, $this->admin);
     $this->assertSame('SonataAdminBundle:CRUD:list__action.html.twig', $field->getTemplate());
     $this->assertSame('Action', $field->getOption('name'));
     $this->assertSame('Action', $field->getOption('code'));
     $this->assertSame(array('show' => array('template' => 'SonataAdminBundle:CRUD:list__action_show.html.twig'), 'edit' => array('template' => 'SonataAdminBundle:CRUD:list__action_edit.html.twig')), $field->getOption('actions'));
 }
 public function optionsProvider()
 {
     $field = new FieldDescription();
     $field->setName('my_field');
     return array(array($field, array(), array('code' => 'my_field')), array($field, array(), array('label' => 'my_field')), array($field, array('code' => 'super code', 'label' => 'super label'), array('code' => 'super code', 'label' => 'super label')));
 }
 public function testGetPaginationParameters()
 {
     $field = new FieldDescription();
     $field->setName('slug');
     $datagrid = $this->getMock('\\Sonata\\AdminBundle\\Datagrid\\DatagridInterface');
     $datagrid->expects($this->once())->method('getValues')->will($this->returnValue(array('_sort_by' => $field)));
     $manager = new ModelManager();
     $this->assertSame(array('filter' => array('_sort_by' => 'slug', '_page' => 42)), $manager->getPaginationParameters($datagrid, 42));
 }