public function __construct(Nette\Forms\Container $container, EntityFormMapper $mapper, ControlFactory $controlFactory = NULL, EntityManager $em = NULL) { $this->container = $container; $this->mapper = $mapper; $this->em = $em ?: $mapper->getEntityManager(); $this->controlFactory = $controlFactory ?: new ControlFactory(); /** @var Nette\Application\UI\Form|Kdyby\DoctrineForms\EntityForm $form */ if (method_exists($form = $container->getForm(FALSE), 'injectEntityMapper')) { $form->injectEntityMapper($this->mapper); } }
/** * @param Container $container * @param ConstraintViolationInterface $violation * @return Nette\Forms\IControl|Nette\Forms\Controls\BaseControl|UI\Form */ private function findControl(Container $container, ConstraintViolationInterface $violation) { if (!($m = Nette\Utils\Strings::split('.' . $violation->getPropertyPath(), '~([\\.\\[])~'))) { return $container->getForm(); // apply the error to form } $control = $container; while (($type = array_shift($m)) !== NULL && $control) { if (empty($type)) { continue; } $step = array_shift($m); if ($type === '[') { $step = substr($step, 0, -1); } $control = $control->getComponent($step, FALSE); } return $control instanceof Nette\Forms\IControl ? $control : $container->getForm(); }
/** * @param Forms\Container $container * @param IGroupConfig $groupConfig * @return Forms\ControlGroup */ private static function getControlGroup(Forms\Container $container, IGroupConfig $groupConfig) { $form = $container->getForm(); $group = $form->getGroup($groupConfig->getLabel()); if ($group === NULL) { // Create group $group = $form->addGroup($groupConfig->getLabel(), FALSE); foreach ($groupConfig->getOptions() as $key => $value) { $group->setOption($key, $value); } } return $group; }
protected function validate() { $this->mapper->runValidation(function (ValidatorInterface $validatorInterface) { return $validatorInterface->validatePropertyValue($this->wrappedEntity->getEntity(), $this->component->name, $this->collection); }, $this->component instanceof BaseControl ? $this->component : $this->component->getForm()); }
/** * @param Container $container * @param ConstraintViolationInterface $violation * @return Nette\Forms\IControl|Nette\Forms\Controls\BaseControl|Nette\Application\UI\Form */ protected function findControl(Container $container, ConstraintViolationInterface $violation) { // propertyPath eg. addresses[1].street $path = preg_split('/\\]\\.|\\.|\\[|\\]/', $violation->getPropertyPath(), -1, PREG_SPLIT_NO_EMPTY); $control = $container; while (($step = array_shift($path)) !== NULL && $control) { $control = $control->getComponent($step, FALSE); } return $control instanceof Nette\Forms\IControl || $control instanceof IContainer ? $control : $container->getForm(); }