/**
  * @param IControlConfig $config
  * @return NULL|Controls\MultiChoiceControl
  */
 public function createControl(IControlConfig $config)
 {
     $control = NULL;
     if ($config->getType() === IControlConfig::CHECKBOX_LIST) {
         $control = new Controls\CheckboxList($config->getLabel());
     } elseif ($config->getType() === IControlConfig::MULTI_SELECT) {
         $control = new Controls\MultiSelectBox($config->getLabel());
     }
     // Setup items
     if ($control && ($items = $this->helper->processItems($control, $config)) !== NULL) {
         $control->setItems($items);
     }
     return $control;
 }
 /**
  * @param IControlConfig $config
  * @return NULL|Controls\ChoiceControl
  */
 public function createControl(IControlConfig $config)
 {
     $control = NULL;
     if ($config->getType() === IControlConfig::RADIO_LIST) {
         $control = new Controls\RadioList($config->getLabel());
     } elseif ($config->getType() === IControlConfig::SELECT) {
         $control = new Controls\SelectBox($config->getLabel());
         $control->setPrompt($config->getOption(IControlConfig::PROMPT) ?: FALSE);
     }
     // Setup items
     if ($control && ($items = $this->helper->processItems($control, $config)) !== NULL) {
         $control->setItems($items);
     }
     return $control;
 }
Beispiel #3
0
 /**
  * Create control from configuration or return NULL if factory does not match config.
  *
  * @param IControlConfig $config
  * @return NULL|BaseControl
  */
 public function createControl(IControlConfig $config)
 {
     if ($config->getType() === IControlConfig::DATE_TIME) {
         $dateFormat = $config->getOption(self::DATE_FORMAT, self::DEFAULT_DATE_FORMAT);
         $control = new DateTimeControl($config->getLabel(), $dateFormat);
         return $control;
     }
     return NULL;
 }
Beispiel #4
0
 protected function mapChoice(Constraints\Choice $constraint, IControlConfig $config)
 {
     if ($config->getType() === "string") {
         if ($constraint->multiple) {
             $config->setType(IControlConfig::CHECKBOX_LIST);
         } else {
             $config->setType(IControlConfig::RADIO_LIST);
         }
     }
 }
 /**
  * Add class after control creation.
  *
  * @param BaseControl $control
  * @param IControlConfig $config
  * @return mixed
  */
 public function afterCreateControl(BaseControl $control, IControlConfig $config)
 {
     switch ($config->getType()) {
         case IControlConfig::DATE_TIME:
             $control->controlPrototype->class[] = 'input-datetime';
             break;
         case IControlConfig::DATE:
             $control->controlPrototype->class[] = 'input-date';
             break;
         case IControlConfig::TIME:
             $control->controlPrototype->class[] = 'input-time';
             break;
     }
 }
 /**
  * Create control from configuration or return NULL if factory does not match config.
  *
  * @param IControlConfig $config
  * @throws \NForms\Exceptions\InvalidStateException
  * @return NULL|BaseControl
  */
 public function createControl(IControlConfig $config)
 {
     if ($config->getType() === self::TYPE) {
         if (($itemsCallback = $config->getOption(self::ITEMS_CALLBACK)) === NULL) {
             throw new InvalidStateException("Missing NForms\\Extensions\\DependentSelectBox::DATA_CALLBACK option in control configuration.");
         }
         $callback = function ($form, $input) use($config, $itemsCallback) {
             $items = call_user_func_array($itemsCallback, func_get_args());
             return $this->helper->processItems($input, $config, $items);
         };
         $parents = $config->getOption(self::PARENTS);
         $control = new DependentSelectBox($config->getLabel(), $callback, $parents ?: array());
         $control->setPrompt($config->getOption(self::PROMPT) ?: FALSE);
         return $control;
     }
     return NULL;
 }
 /**
  * Opportunity to influence control config before control creation.
  *
  * @param IControlConfig $config
  * @return mixed
  */
 public function beforeCreateControl(IControlConfig $config)
 {
     if ($config->getType() === self::TYPE) {
         $config->setOption(ApplyButtonFactory::ADD_APPLY_BUTTON);
     }
 }