protected function fieldset(WP_Form_Element_Fieldset $element) { $children = $this->render_children($element); $legend = $this->get_legend($element); $output = sprintf('<fieldset %s>%s%s</fieldset>', WP_Form_View::prepare_attributes($element->get_all_attributes()), $legend, $children); return $output; }
protected function input(WP_Form_Element $element) { $attributes = $element->get_all_attributes(); $attributes = WP_Form_View::prepare_attributes($attributes); $template = '<input %s />'; return sprintf($template, $attributes); }
protected function button(WP_Form_Element $element) { $attributes = $element->get_all_attributes(); $label = $element->get_label(); $attributes = WP_Form_View::prepare_attributes($attributes); $template = '<button %s>%s</button>'; return sprintf($template, $attributes, $label); }
protected function markup(WP_Form_Element $element) { $content = $element->get_content(); $attributes = $element->get_all_attributes(); unset($attributes['value'], $attributes['type']); $attributes = WP_Form_View::prepare_attributes($attributes); $template = '<div %s>%s</div>'; return sprintf($template, $attributes, $content); }
protected function textarea(WP_Form_Element $element) { $attributes = $element->get_all_attributes(); $value = ''; if (isset($attributes['value'])) { $value = esc_textarea($attributes['value']); unset($attributes['value']); } $attributes = WP_Form_View::prepare_attributes($attributes); $template = '<textarea %s>%s</textarea>'; return sprintf($template, $attributes, $value); }
protected function wrapper(WP_Form_Element_Wrapper $element) { $children = $this->render_children($element); $attributes = $element->get_all_attributes(); // Because this is just a tag (div, span) we don't need this attrs in tag. unset($attributes['name'], $attributes['tag_name'], $attributes['type'], $attributes['value']); $attributes = WP_Form_View::prepare_attributes($attributes); $tag_name = $element->get_attribute('tag_name'); if (empty($tag_name)) { $tag_name = 'div'; } $output = sprintf('<%1$s %2$s>%3$s</%1$s>', $tag_name, $attributes, $children); return $output; }
protected function select(WP_Form_Element_Select $element) { $attributes = $element->get_all_attributes(); $attributes = WP_Form_View::prepare_attributes($attributes); $template = '<select %s>%s</select>'; $options = $element->get_options(); $options_html = ''; $selected = $element->get_selected(); foreach ($options as $key => $value) { if (is_array($value)) { $options_html .= $this->optgroup($key, $value, $selected); } else { $options_html .= $this->option($key, $value, $selected); } } return sprintf($template, $attributes, $options_html); }
public function render(WP_Form_Component $element) { $errors = $element->get_errors(); if ($errors) { $output = ''; $args = wp_parse_args($this->args, array('tag' => 'ul', 'tag_single' => 'li', 'class_single' => 'error', 'attributes' => array(), 'position' => self::POSITION_AFTER)); foreach ($errors as $error) { $output .= '<' . $args['tag_single'] . ' class="' . $args['class_single'] . '">' . $error . '</' . $args['tag_single'] . '>'; } $output = sprintf('<%1$s %2$s>%3$s</%1$s>', $args['tag'], WP_Form_View::prepare_attributes($args['attributes']), $output); switch ($args['position']) { case self::POSITION_AFTER: return $this->component_view->render($element) . $output; break; case self::POSITION_BEFORE: default: return $output . $this->component_view->render($element); break; } } return $this->component_view->render($element); }
private function open_tag($tag, $attributes = array()) { return sprintf("<%s %s>", $tag, WP_Form_View::prepare_attributes($attributes)); }
public function form(WP_Form $form) { $children = $this->render_children($form); $output = sprintf('<form %s>%s</form>', WP_Form_View::prepare_attributes($form->get_all_attributes()), $children); return $output; }