Esempio n. 1
0
 private function getSelectHtml()
 {
     $name = $this->getName();
     $options = $this->getOptions();
     $options = $options ? $options : $this->setOptionsFromFolder()->getOptions();
     if ($options) {
         $generator = new Generator();
         $generator->newElement('select', array('data-mxid' => $this->mxid, 'class' => "matrix-select-{$name}", 'data-group' => $this->getForm()->getGroup()));
         $default = $this->getSetting('default');
         foreach ($options as $name => $value) {
             $attr['value'] = $value;
             if ($default === $value) {
                 $attr['selected'] = 'selected';
             } else {
                 unset($attr['selected']);
             }
             $generator->appendInside('option', $attr, $name);
         }
         $select = $generator->getString();
     } else {
         $paths = Config::getPaths();
         $dir = $paths['matrix_folder'] . '/' . $name;
         $select = "<div class=\"tr-dev-alert-helper\"><i class=\"icon tr-icon-bug\"></i> Add a files for Matrix <code>{$dir}</code> and add your matrix files to it.</div>";
     }
     return $select;
 }
Esempio n. 2
0
 /**
  * Covert Select to HTML string
  */
 public function getString()
 {
     $default = $this->getSetting('default');
     $this->setAttribute('name', $this->getNameAttributeString());
     $option = $this->getValue();
     $option = !is_null($option) ? $option : $default;
     $generator = new Generator();
     $generator->newElement('select', $this->getAttributes());
     foreach ($this->options as $key => $value) {
         if (is_array($value)) {
             $optgroup = new Generator();
             $optgroup->newElement('optgroup', ['label' => $key]);
             foreach ($value as $k => $v) {
                 $attr['value'] = $v;
                 if ($option == $v && isset($option)) {
                     $attr['selected'] = 'selected';
                 } else {
                     unset($attr['selected']);
                 }
                 $optgroup->appendInside('option', $attr, (string) $k);
             }
             $generator->appendInside($optgroup);
         } else {
             $attr['value'] = $value;
             if ($option == $value && isset($option)) {
                 $attr['selected'] = 'selected';
             } else {
                 unset($attr['selected']);
             }
             $generator->appendInside('option', $attr, (string) $key);
         }
     }
     return $generator->getString();
 }
Esempio n. 3
0
 /**
  * Covert Checkbox to HTML string
  */
 public function getString()
 {
     $name = $this->getNameAttributeString();
     $this->removeAttribute('name');
     $default = $this->getSetting('default');
     $option = $this->getValue();
     $checkbox = new Generator();
     $field = new Generator();
     if ($option == '1' || !is_null($option) && $option === $this->getAttribute('value')) {
         $this->setAttribute('checked', 'checked');
     } elseif ($default === true && is_null($option)) {
         $this->setAttribute('checked', 'checked');
     }
     $checkbox->newInput('checkbox', $name, '1', $this->getAttributes());
     $field->newElement('label')->appendInside($checkbox)->appendInside('span', array(), $this->getSetting('text'));
     if ($default !== false) {
         $hidden = new Generator();
         $field->prependInside($hidden->newInput('hidden', $name, '0'));
     }
     return $field->getString();
 }