Пример #1
0
 /**
  * Fügt dieses Objekt einem anderen HTML-Objekt als innerHtml hinzu
  * @param Html $element
  * @return $this
  */
 public function addTo($element)
 {
     $element->text($this);
     return $this;
 }
 /**
  * Fügt dem Control ein HTML-Literal oder -Objekt hinzu
  * @param string|HtmlOutputInterface $html
  * @return $this
  */
 public function text($html)
 {
     $this->innerHtml->text($html);
     return $this;
 }
 /**
  * @inheritdoc
  */
 public function toHtml()
 {
     $select = Html::create('select')->css('lookup')->css('form-control')->addCssClasses($this->cssClasses)->attr('name', $this->name)->attr('id', $this->id);
     if ($this->groupfield !== null) {
         $select->css('grouped');
     }
     if ($this->multiple) {
         $select->attr('multiple', 'multiple');
         $select->attr('name', $this->name . '[]');
     }
     if ($this->readOnly) {
         $select->attr('disabled', 'disabled');
     }
     // Falls null-Wert angezeigt werden soll
     if ($this->showNullValue) {
         Html::create('option')->attr('value', $this->nullValue)->text($this->nullText)->addTo($select);
     }
     $groupValue = null;
     $optGroup = null;
     // Objekte laden, damit die Formatierungen angewendet werden
     $items = $this->lookupentity->filter($this->filter, 3000);
     if (!$this->parent instanceof SubmitDataControl && count($items) > 50) {
         $this->setUseChosen(true);
     }
     foreach ($items as $curItem) {
         // Gruppenkopf
         if ($this->groupfield != null && $groupValue !== $this->getEntityText($curItem, $this->groupfield)) {
             $optGroup = new Html('optgroup');
             $optGroup->attr('label', $this->getEntityText($curItem, $this->groupfield))->addTo($select);
             $groupValue = $this->getEntityText($curItem, $this->groupfield);
         }
         $text = $this->getEntityText($curItem, $this->textfield);
         if ($this->textfield2 !== null) {
             $text .= ', ' . $this->getEntityText($curItem, $this->textfield2);
         }
         $option = new Html('option');
         $option->attr('value', $curItem->val($this->valuefield))->text($text);
         if ($curItem->val($this->valuefield) == $this->selectedValue) {
             $option->attr('selected', 'selected');
         }
         if ($optGroup !== null) {
             $optGroup->text($option);
         } else {
             $select->text($option);
         }
     }
     return $select->render();
 }