示例#1
0
 /**
  * Returns the class associated to a FieldDescriptionInterface if any defined
  *
  * @throws RuntimeException
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @return bool|string
  */
 public function getFormTypeName(FieldDescriptionInterface $fieldDescription)
 {
     $typeName = false;
     // the user redefined the mapping type, use the default built in definition
     if (!$fieldDescription->getFieldMapping() || $fieldDescription->getType() != $fieldDescription->getMappingType()) {
         $typeName = array_key_exists($fieldDescription->getType(), $this->formTypes) ? $this->formTypes[$fieldDescription->getType()] : false;
     } else {
         if ($fieldDescription->getOption('form_field_type', false)) {
             $typeName = $fieldDescription->getOption('form_field_type', false);
         } else {
             if (array_key_exists($fieldDescription->getType(), $this->formTypes)) {
                 $typeName = $this->formTypes[$fieldDescription->getType()];
             }
         }
     }
     if (!$typeName) {
         throw new \RuntimeException(sprintf('No known form type for field `%s` (`%s`) is implemented.', $fieldDescription->getFieldName(), $fieldDescription->getType()));
     }
     return $typeName;
 }