Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function renderOptions(array $options, array $selectedOptions = [])
 {
     $template = '<option %s>%s</option>';
     $optionStrings = [];
     $escapeHtml = $this->getEscapeHtmlHelper();
     foreach ($options as $key => $optionSpec) {
         $value = '';
         $label = '';
         $selected = false;
         $disabled = false;
         if (is_scalar($optionSpec)) {
             $optionSpec = ['label' => $optionSpec, 'value' => $key];
         }
         if (isset($optionSpec['options']) && is_array($optionSpec['options'])) {
             $optionStrings[] = $this->renderOptgroup($optionSpec, $selectedOptions);
             continue;
         }
         if (isset($optionSpec['value'])) {
             $value = $optionSpec['value'];
         }
         if (isset($optionSpec['label'])) {
             $label = $optionSpec['label'];
         }
         if (isset($optionSpec['selected'])) {
             $selected = $optionSpec['selected'];
         }
         if (isset($optionSpec['disabled'])) {
             $disabled = $optionSpec['disabled'];
         }
         if (ArrayUtils::inArray($value, $selectedOptions)) {
             $selected = true;
         }
         if (empty($optionSpec['translator_disabled']) && null !== ($translator = $this->getTranslator())) {
             $label = $translator->translate($label, $this->getTranslatorTextDomain());
         }
         $attributes = compact('value', 'selected', 'disabled');
         if (isset($optionSpec['attributes']) && is_array($optionSpec['attributes'])) {
             $attributes = array_merge($attributes, $optionSpec['attributes']);
         }
         $this->validTagAttributes = $this->validOptionAttributes;
         $optionStrings[] = sprintf($template, $this->createAttributesString($attributes), $escapeHtml($label));
     }
     return implode("\n", $optionStrings);
 }