Exemplo n.º 1
0
 /**
  * @param BaseEntity $entity
  * @param Form $form
  */
 public function setEntityToForm(BaseEntity &$entity, Form &$form)
 {
     /** @var BaseControl $control */
     foreach ($form->getComponents() as $control) {
         /** @noinspection PhpParamsInspection */
         $value = $this->getEntityValue($entity, $control);
         if (!$value) {
             continue;
         }
         // do base
         $this->mapValueToForm($value, $control);
     }
 }
 protected function createComponentPostForm()
 {
     $form = new Form();
     $form->addText('title', 'Titulek:')->setRequired();
     $form->addTextArea('content', 'Obsah:', 55, 8)->setRequired()->setAttribute('class', 'mceEditor');
     $form->getElementPrototype()->onsubmit('tinyMCE.triggerSave()');
     $form->addSubmit('send', 'Vložit článek');
     foreach ($form->getComponents(TRUE, 'SubmitButton') as $button) {
         if (!$button->getValidationScope()) {
             continue;
         }
         $button->getControlPrototype()->onclick('tinyMCE.triggerSave()');
     }
     // setup form rendering
     $renderer = $form->getRenderer();
     $renderer->wrappers['controls']['container'] = NULL;
     $renderer->wrappers['pair']['container'] = 'div class="form-group text-center"';
     $renderer->wrappers['pair']['.error'] = 'has-error';
     $renderer->wrappers['control']['container'] = 'div class="col-sm-10"';
     $renderer->wrappers['label']['container'] = 'div class="control-label text-center col-sm-1"';
     $renderer->wrappers['control']['description'] = 'span class=help-block';
     $renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
     // make form and controls compatible with Twitter Bootstrap
     $form->getElementPrototype()->class('form-horizontal');
     foreach ($form->getControls() as $control) {
         if ($control instanceof Controls\Button) {
             $control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
             $usedPrimary = TRUE;
         } elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
             $control->getControlPrototype()->addClass('form-control');
         } elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
             $control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
         }
     }
     $form->onSuccess[] = array($this, 'postFormSucceeded');
     return $form;
 }