Пример #1
0
 /**
  * @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;
 }
Пример #2
0
 /**
  * @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;
 }
Пример #3
0
 /**
  * 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;
 }