Example #1
0
 /**
  * @param IControlConfig $controlConfig
  * @throws \NForms\Exceptions\FieldNotFoundException
  */
 protected function setupControlConfig(IControlConfig $controlConfig)
 {
     $name = $controlConfig->getFieldName();
     $classMetadata = $this->getClassMetadata();
     if ($classMetadata->hasField($name)) {
         $controlConfig->setMapping($classMetadata->getFieldMapping($name));
         $controlConfig->setType($classMetadata->getFieldType($name));
     } elseif ($classMetadata->hasAssociation($name)) {
         $controlConfig->setMapping($classMetadata->getAssociationMapping($name));
         $controlConfig->setTargetClass($classMetadata->getAssociationTargetClass($name));
         $controlConfig->setType($classMetadata->isSingleValuedAssociation($name) ? IControlConfig::TO_ONE : IControlConfig::TO_MANY);
     } else {
         throw new FieldNotFoundException("Field/association '{$name}' was not found in '{$this->targetClass}' class.");
     }
     $controlConfig->setParentClassName($classMetadata->getClass());
     $controlConfig->setLabel($this->getLabelFor($controlConfig));
     $constraintMetadata = $this->getConstraintMetadata();
     if ($constraintMetadata) {
         $controlConfig->setConstraints($constraintMetadata->getConstraintsForField($name));
     }
 }