public function render(WP_Form_Component $element)
 {
     $label = '';
     if (is_callable(array($element, 'get_label'))) {
         $label = $element->get_label();
     }
     if (empty($label)) {
         return $this->component_view->render($element);
     }
     $position = self::POSITION_BEFORE;
     if (!empty($this->args['position'])) {
         $position = $this->args['position'];
     }
     $class = apply_filters('wp_form_label_html_class', 'form-label');
     switch ($position) {
         case self::POSITION_AFTER:
             $template = '%4$s <label for="%1$s" class="%2$s">%3$s</label>';
             break;
         case self::POSITION_SURROUND:
             $template = '<label for="%1$s" class="%2$s">%4$s %3$s</label>';
             break;
         case self::POSITION_BEFORE:
         default:
             $template = '<label for="%1$s" class="%2$s">%3$s</label> %4$s';
             break;
     }
     return sprintf($template, $element->get_id(), $class, $label, $this->component_view->render($element));
 }
Exemple #2
0
 public function render(WP_Form_Component $element)
 {
     $type = $element->get_type();
     if (method_exists($this, $type)) {
         return call_user_func(array($this, $type), $element);
     }
     return '';
 }
 /**
  * Add a child component
  *
  * @param WP_Form_Component $element
  * @param string $key A unique key for the component.
  *                    Any existing component with the same key
  *                    will be overwritten. If $key is empty,
  *                    an attempt will be made to generate a
  *                    unique key.
  * @throws InvalidArgumentException
  * @return $this
  */
 public function add_element(WP_Form_Component $element, $key = '')
 {
     if (empty($key)) {
         $key = $element->get_name();
     }
     if (empty($key)) {
         throw new InvalidArgumentException(__('Cannot add nameless element to a fieldset', 'wp-forms'));
     }
     $this->elements[$key] = $element;
     return $this;
 }
 public function render(WP_Form_Component $element)
 {
     $type = $element->get_type();
     if (method_exists($this, $type)) {
         return call_user_func(array($this, $type), $element);
     } elseif ($element instanceof WP_Form_Element) {
         return $this->markup($element);
         // fallback to generic <input />
     }
     return '';
 }
 public function render(WP_Form_Component $element)
 {
     $errors = $element->get_errors();
     $output = '';
     if ($errors) {
         $output = '<ul class="errors">';
         foreach ($errors as $e) {
             $output .= '<li class="error">' . $e . '</li>';
         }
         $output .= '</ul>';
     }
     return $output . $this->component_view->render($element);
 }
 public function render(WP_Form_Component $element)
 {
     $description = '';
     if (is_callable(array($element, 'get_description'))) {
         $description = $element->get_description();
     }
     if ($description) {
         $args = wp_parse_args($this->args, array('tag' => 'p', 'attributes' => array()));
         if (empty($args['attributes']['class'])) {
             $args['attributes']['class'] = 'description';
         }
         $args['attributes']['class'] = apply_filters('wp_form_description_html_class', $args['attributes']['class']);
         $start = $this->open_tag($args['tag'], $args['attributes']);
         $end = $this->close_tag($args['tag']);
         $description = $start . $description . $end;
     }
     return $this->component_view->render($element) . $description;
 }
 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);
 }
 protected function prepare_form_values(WP_Form_Component $component)
 {
     if ($component instanceof WP_Form_Aggregate) {
         foreach ($component->get_children() as $child) {
             $this->prepare_form_values($child);
         }
     } elseif ($component instanceof WP_Form_Element) {
         $value = $this->get_value($component->get_name());
         $component->set_value($value);
     }
 }
 /**
  * @param WP_Form_Component $element
  * @return string
  */
 protected function render_child(WP_Form_Component $element)
 {
     return $element->render();
 }