Example #1
0
 /**
  * Render strainer for a select element
  *
  * @param \FrenchFrogs\Table\Column\Strainer\Select $strainer
  * @return string
  */
 public function strainerSelect(Column\Strainer\Select $strainer)
 {
     $element = $strainer->getElement();
     $element->addStyle('width', '100%');
     $element->addClass(Style::FORM_ELEMENT_CONTROL);
     $options = '';
     if ($element->hasPlaceholder()) {
         $options .= html('option', ['value' => null], $element->getPlaceholder());
     }
     foreach ($element->getOptions() as $value => $label) {
         $attr = ['value' => $value];
         if ($element->hasValue() && in_array($value, $element->getValue())) {
             $attr['selected'] = 'selected';
         }
         $options .= html('option', $attr, $label);
     }
     return html('select', $element->getAttributes(), $options);
 }