public function handle($name, array $options, ClassMetadata $classMetadata, Configuration $configuration)
 {
     if (!($mapping = MetadataHelpers::getAssociationMapping($classMetadata, $name, ClassMetadata::MANY_TO_MANY))) {
         return NULL;
     }
     $options += ['control' => ControlFactory::MULTI_SELECT_BOX, 'fill' => TRUE];
     $control = ControlFactory::create($options['control'], ['\\Nette\\Forms\\Controls\\MultiChoiceControl'], ControlFactory::MULTI_SELECT_BOX);
     if (empty($options['caption'])) {
         $control->caption = $configuration->getLabelingStrategy()->getControlLabel($name, $classMetadata);
     } else {
         $control->caption = $options['caption'];
     }
     $this->fillOptions($options, $control, $mapping);
     return new ControlBuilder($control);
 }
 public function handle($name, array $options, ClassMetadata $classMetadata, Configuration $configuration)
 {
     if (!$classMetadata->hasField($name)) {
         return NULL;
     }
     $mapping = $classMetadata->getFieldMapping($name);
     $controlName = empty($options['control']) ? $this->getControlByType($mapping['type']) : $options['control'];
     $control = ControlFactory::create($controlName, ['\\Nette\\Forms\\Controls\\BaseControl'], ControlFactory::TEXT_INPUT);
     if (empty($options['caption'])) {
         $control->caption = $configuration->getLabelingStrategy()->getControlLabel($name, $classMetadata);
     } else {
         $control->caption = $options['caption'];
     }
     return new ControlBuilder($control);
 }
 public function handle($name, array $options, ClassMetadata $classMetadata, Configuration $configuration)
 {
     if (!($mapping = MetadataHelpers::getAssociationMapping($classMetadata, $name, [ClassMetadata::MANY_TO_ONE, ClassMetadata::ONE_TO_ONE]))) {
         return NULL;
     }
     $options += ['control' => ControlFactory::SELECT_BOX, 'fill' => TRUE];
     $control = ControlFactory::create($options['control'], self::$allowedControls, ControlFactory::SELECT_BOX);
     if (empty($options['caption'])) {
         $control->caption = $configuration->getLabelingStrategy()->getControlLabel($name, $classMetadata);
     } else {
         $control->caption = $options['caption'];
     }
     if ($control instanceof ChoiceControl) {
         $this->setPrompt($options, $control, $mapping);
         $this->fillOptions($options, $control, $mapping);
     }
     return new ControlBuilder($control);
 }
 /**
  * @param string
  * @param array
  * @return IBuilder
  * @throws \Exception
  */
 protected function createBuilder($name, $options = [])
 {
     $builder = $this->configuration->getHandler()->handle($name, $options, $this->metadata, $this->configuration);
     if ($builder === NULL) {
         throw new \RuntimeException("No satisfying handler found.");
         //todo better exception
     }
     return $builder;
 }
 /**
  * @param object|string
  * @param bool|null
  */
 public function create($entity, $createMapper = self::AUTO)
 {
     $className = is_string($entity) ? $entity : get_class($entity);
     $classMetadata = $this->entityManager->getClassMetadata($className);
     /** @var FormBuilder $builder */
     $builder = $this->configuration->getHandler()->handle(NULL, [], $classMetadata, $this->configuration);
     if (!$builder instanceof FormBuilder) {
         throw new UnexpectedValueException("Builder created by root handler must be an instance of FormBuilder");
     }
     if ($createMapper === TRUE || $createMapper === self::AUTO && is_object($entity)) {
         if (!is_object($entity)) {
             throw new InvalidArgumentException("If you want to create mapper, you have to pass an entity.");
         }
         if (!$this->mapperFactory) {
             throw new InvalidStateException("MapperFactory has not been injected.");
         }
         $form = $builder->getForm();
         if (!$form instanceof IFormWithMapper) {
             throw new InvalidStateException("Form does not implement \\Librette\\Forms\\IFormWithMapper");
         }
         $form->setMapper($this->mapperFactory->create($entity));
     }
     return $builder;
 }