/** * * @throws EE_Error * @return string of html to display the field */ public function display() { if (!$this->_input instanceof EE_Form_Input_With_Options_Base) { throw new EE_Error(sprintf(__('Cannot use Select Multiple Display Strategy with an input that doesn\'t have options', "event_espresso"))); } $html = EEH_HTML::nl(0, 'select'); $html .= '<select multiple'; $html .= ' id="' . $this->_input->html_id() . '"'; $html .= ' name="' . $this->_input->html_name() . '[]"'; $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); $html .= ' class="' . $class . '"'; // add html5 required $html .= $this->_input->required() ? ' required' : ''; $html .= ' style="' . $this->_input->html_style() . '"'; $html .= '>'; EE_Registry::instance()->load_helper('Array'); EEH_HTML::indent(1, 'select'); if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { throw new EE_Error(sprintf(__("Select multiple display strategy does not allow for nested arrays of options.", "event_espresso"))); } else { $html .= $this->_display_options($this->_input->options()); } $html .= EEH_HTML::nl(-1, 'select') . "</select>"; return $html; }
/** * Displays a flat list of options as option tags * @param array $options * @return string */ protected function _display_options($options) { $html = ''; EEH_HTML::indent(1, 'option'); foreach ($options as $value => $display_text) { $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; $html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>'; } EEH_HTML::indent(-1, 'option'); return $html; }
/** * return a newline and tabs ("nl" stands for "new line") * * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) * @param string $tag * @return string - newline character plus # of indents passed (can be + or -) */ public static function nl($indent = 0, $tag = 'none') { $html = "\n"; EEH_HTML::indent($indent, $tag); for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) { $html .= "\t"; } return $html; }