Example #1
0
 /**
  * Build container according given container configuration.
  *
  * @param IFormConfig $containerConfig
  * @param Forms\Container  $container
  * @throws \NForms\Exceptions\InvalidArgumentException
  * @return void
  */
 public function build(IFormConfig $containerConfig, Forms\Container $container)
 {
     // Set container class
     if ($container instanceof IContainer) {
         $container->setClassName($containerConfig->getTargetClass());
     }
     if ($container instanceof IOptions) {
         $container->setOption(self::VALIDATION_GROUPS_OPTION, $containerConfig->getValidationGroups());
     }
     // Build container components
     foreach ($containerConfig->getAll() as $componentConfig) {
         if ($componentConfig instanceof IContainerConfig) {
             $component = $this->createContainer($componentConfig, $container);
         } elseif ($componentConfig instanceof IControlConfig) {
             $component = $this->createControl($componentConfig, $container);
             // Disabled?
             if ($componentConfig->getDisabled()) {
                 $component->setDisabled();
             }
             // Locked?
             if ($componentConfig->getReadonly()) {
                 $control = $component instanceof ApplyButtonWrapper ? $component->getWrappedControl() : $component;
                 $control->setOmitted();
                 $control->getControlPrototype()->addAttributes(array('readonly' => TRUE));
                 $reflection = new \ReflectionClass($control);
                 $property = $reflection->getProperty('disabled');
                 $property->setAccessible(TRUE);
                 $property->setValue($control, TRUE);
             }
         } else {
             throw new InvalidArgumentException("Expected IContainerConfig/IControlConfig given '" . (is_object($componentConfig) ? get_class($componentConfig) : gettype($componentConfig)) . "'.");
         }
         // Set options
         /** @var Forms\Controls\BaseControl|IContainer $component */
         $component->setOption(IObjectMapper::FIELD_NAME, $componentConfig->getFieldName());
         foreach ($componentConfig->getOptions() as $key => $value) {
             $component->setOption($key, $value);
         }
     }
 }
Example #2
0
 /** {@inheritdoc} */
 public function getValidationGroups()
 {
     return $this->formConfig->getValidationGroups();
 }