protected static function listSelections($selection, $listData, &$htmlOptions) { $raw = isset($htmlOptions['encode']) && !$htmlOptions['encode']; $content = ''; if (isset($htmlOptions['prompt'])) { $content .= '<li data="">' . strtr($htmlOptions['prompt'], array('<' => '<', '>' => '>')) . "</li>\n"; unset($htmlOptions['prompt']); } if (isset($htmlOptions['empty'])) { if (!is_array($htmlOptions['empty'])) { $htmlOptions['empty'] = array('' => $htmlOptions['empty']); } foreach ($htmlOptions['empty'] as $value => $label) { $content .= '<li data="' . Html::encode($value) . '">' . strtr($label, array('<' => '<', '>' => '>')) . "</li>\n"; } unset($htmlOptions['empty']); } if (isset($htmlOptions['options'])) { $options = $htmlOptions['options']; unset($htmlOptions['options']); } else { $options = array(); } $key = isset($htmlOptions['key']) ? $htmlOptions['key'] : 'primaryKey'; if (is_array($selection)) { foreach ($selection as $i => $item) { if (is_object($item)) { $selection[$i] = $item->{$key}; } } } else { if (is_object($selection)) { $selection = $selection->{$key}; } } foreach ($listData as $key => $value) { if (is_array($value)) { $content .= '<optgroup label="' . ($raw ? $key : self::encode($key)) . "\">\n"; $dummy = array('options' => $options); if (isset($htmlOptions['encode'])) { $dummy['encode'] = $htmlOptions['encode']; } $content .= $this->listOptions($selection, $value, $dummy); $content .= '</optgroup>' . "\n"; } else { $attributes = array('data' => (string) $key, 'encode' => !$raw); if (!is_array($selection) && !strcmp($key, $selection) || is_array($selection) && in_array($key, $selection)) { $attributes['selected'] = 'selected'; } if (isset($options[$key])) { $attributes = array_merge($attributes, $options[$key]); } $str = $raw ? (string) $value : Html::encode((string) $value) . "\n"; $content .= Html::tag('li', $str, $attributes); } } if (!empty($htmlOptions['name'])) { if (!is_array($selection)) { $content .= '<input type="hidden" value="' . $selection . '" id="' . $htmlOptions['id'] . '" name="' . $htmlOptions['name'] . '"/>'; } } unset($htmlOptions['name']); unset($htmlOptions['key']); $htmlOptions['id'] .= '_select'; return $content; }
/** * @inheritdoc */ public function init() { if (!isset($this->options['id'])) { $this->options['id'] = $this->getId(); } if ($this->requiresPjax()) { ob_start(); ob_implicit_flush(false); $view = $this->getView(); $view->clear(); $view->beginPage(); $view->head(); $view->beginBody(); if ($view->title !== null) { echo Html::tag('title', Html::encode($view->title)); } } else { echo Html::beginTag('div', $this->options); } }