Exemple #1
0
 public function build()
 {
     if ($this->selected) {
         $this->attribute['selected'] = false;
     }
     if (!$this->checkAttribute('value') && !empty($this->inner)) {
         $this->attribute['value'] = $this->inner;
     }
     if ($this->checkAttribute('value') && empty($this->inner)) {
         $this->inner = $this->attribute['value'];
     }
     return parent::build();
 }
Exemple #2
0
 /**
  *
  * {@inheritdoc}
  *
  * @see \Core\Html\AbstractHtml::build()
  */
 public function build()
 {
     foreach ($this->options as $key => $option) {
         if (is_array($option)) {
             $this->inner .= '<optgroup label="' . $key . '">';
             foreach ($option as $opt) {
                 $this->inner .= $this->buildOption($opt);
             }
             $this->inner .= '</optgroup>';
         } else {
             $this->inner .= $this->buildOption($option);
         }
     }
     if ($this->getMultiple()) {
         $this->setName($this->getName() . '[]');
     }
     return parent::build();
 }
Exemple #3
0
 private function buildAbstractForm()
 {
     // What type of control do we have to handle?
     $type = $this->control->getData('control');
     // ( Get control name
     $name = $this->control->getName();
     // Set BS group class
     switch ($type) {
         case 'radio':
             $container = '<div class="radio{state}"><label>{control}{label}{help}</label></div>';
             break;
         case 'checkbox':
             $container = '<div class="checkbox{state}"><label>{control}{label}{help}</label></div>';
             break;
         case 'button':
         case 'hidden':
             $container = $this->display_mode == 'h' ? '<div class="form-group{state}">{control}</div>' : '{control}';
             break;
         default:
             $container = '<div class="form-group{state}{size}">{label}{control}' . ($this->display_mode == 'v' ? '{help}{error}' : '') . '</div>';
             if (property_exists($this->control, 'html')) {
                 $this->control->html->addCss('form-control');
             } else {
                 $this->control->addCss('form-control');
             }
             break;
     }
     // Hidden controls dont need any label or other stuff to display
     if ($type == 'input' && $this->control->getType() == 'hidden') {
         return $this->control->build();
     }
     // Has the control a specific size?
     $control_size = $this->control->getControlSize();
     $container = str_replace('{size}', $control_size ? ' form-group-' . $control_size : '', $container);
     // Insert groupstate
     $container = str_replace('{state}', $this->errors ? ' has-error' : '', $container);
     $label = '';
     // Add possible label
     if ($this->control->hasLabel() && !$this->control instanceof Checkbox) {
         // Try to find a suitable text as label in our languagefiles
         if (!$this->control->getLabel()) {
             $this->control->setLabel('No label text set');
         }
         // Attach to control id
         $this->control->label->setFor($this->control->getId());
         // Make it a BS control label
         $this->control->label->addCss('control-label');
         // Horizontal forms needs grid size for label
         if ($this->display_mode == 'h') {
             $this->control->label->addCss('col-' . $this->grid_size . '-' . $this->label_width);
         }
         $label = $this->control->label->build();
     }
     // Checkboxes are different
     if ($this->control instanceof Checkbox) {
         $label = $this->control->getLabel();
         // Checkboxes are wrapped by label tags, so we need only the text
         if (empty($label)) {
             $label = 'No label text set.';
         }
     }
     // Insert label into controlcontainer
     $container = str_replace('{label}', $label, $container);
     // Insert dom id of related control for checkbox and radio labels
     if ($type == 'checkbox' || $type == 'radio') {
         $container = str_replace('{id}', $this->control->getId(), $container);
     }
     // Add max file size field before file input field
     if ($this->control instanceof Input && $this->control->getType() == 'file') {
         // Get maximum filesize for uploads
         $max_file_size = $this->di->get('core.io.file')->getMaximumFileUploadSize();
         $max_size_field = $this->factory->create('Form\\Input');
         $max_size_field->setType('hidden');
         $max_size_field->setValue($max_file_size);
         $container = str_replace('{control}', $max_size_field->build() . '{control}', $container);
     }
     // Add hidden field to compare posted value with previous value.
     if ($this->control->hasCompare()) {
         $compare_name = str_replace($name, $name . '_compare', $this->control->getName());
         $compare_control = $this->factory->create('Form\\Input');
         $compare_control->setName($compare_name);
         $compare_control->setType('hidden');
         $compare_control->setValue($this->control->getCompare());
         $compare_control->setId($this->control->getId() . '_compare');
         $container = str_replace('{control}', '{control}' . $compare_control->build(), $container);
     }
     // Add possible validation errors css to control
     if ($this->errors) {
         $this->control->addData('error', implode('<br>', $this->errors));
     }
     // Build control
     if ($this->display_mode == 'h') {
         $control = '<div class="' . (!$this->control->hasLabel() ? 'col-' . $this->grid_size . '-offset-' . $this->label_width . ' ' : '') . 'col-' . $this->grid_size . '-' . (12 - $this->label_width) . '">' . $this->control->build() . '{help}{error}</div>';
     } else {
         $control = $this->control->build();
     }
     if ($this->control->hasElementWidth()) {
         $container = '<div class="' . $this->control->getElementWidth() . '">' . $container . '</div>';
     }
     // Inserc built control in container
     $container = str_replace('{control}', $control, $container);
     // Build possible description
     $help = $this->control->hasDescription() ? '<div class="help-block">' . $this->control->getDescription() . '</div>' : '';
     // Insert description into controlcontainer
     $container = str_replace('{help}', $help, $container);
     // Add possible validation errors css to label and control
     $error = $this->errors ? '<div class="small text-danger">' . implode('<br>', $this->errors) . '</div>' : '';
     // Insert errors into container
     $container = str_replace('{error}', $error, $container);
     return $container;
 }
Exemple #4
0
 public function build()
 {
     $this->attribute['type'] = $this->type;
     return parent::build();
 }
Exemple #5
0
 public function build()
 {
     return parent::build();
 }