Fieldmanager_Field::single_element_markup PHP Method

single_element_markup() public method

Is called by element_markup(), calls form_element().
See also: Fieldmanager_Field::element_markup()
See also: Fieldmanager_Field::form_element()
public single_element_markup ( mixed $value = Null, boolean $is_proto = False ) : string
$value mixed the current value of this element.
$is_proto boolean true to generate a prototype element for Javascript.
return string HTML for a single form element.
    public function single_element_markup($value = Null, $is_proto = False)
    {
        if ($is_proto) {
            $this->is_proto = true;
        }
        $out = '';
        $classes = array('fm-item', 'fm-' . $this->name);
        self::$global_seq++;
        // Drop the fm-group class to hide inner box display if no label is set
        if (!($this->is_group() && (!isset($this->label) || empty($this->label)))) {
            $classes[] = 'fm-' . $this->field_class;
        }
        // Check if the required attribute is set. If so, add the class.
        if ($this->required) {
            $classes[] = 'form-required';
        }
        if ($is_proto) {
            $classes[] = 'fmjs-proto';
        }
        if ($this->is_group() && 'vertical' === $this->tabbed) {
            $classes[] = 'fm-tabbed-vertical';
        }
        $classes = apply_filters('fm_element_classes', $classes, $this->name, $this);
        $out .= sprintf('<div class="%s">', esc_attr(implode(' ', $classes)));
        $label = $this->get_element_label();
        $render_label_after = False;
        // Hide the label if it is empty or if this is a tab since it would duplicate the title from the tab label
        if (!empty($this->label) && !$this->is_tab && $this->one_label_per_item) {
            if ($this->limit != 1) {
                $out .= $this->wrap_with_multi_tools($label, array('fmjs-removable-label'));
            } elseif (!$this->label_after_element) {
                $out .= $label;
            } else {
                $render_label_after = True;
            }
        }
        if (isset($this->description) && !empty($this->description) && !$this->description_after_element) {
            $out .= sprintf('<div class="fm-item-description">%s</div>', $this->escape('description'));
        }
        if (Null === $value && Null !== $this->default_value) {
            $value = $this->default_value;
        }
        $form_element = $this->form_element($value);
        if ($this->limit != 1 && (!$this->one_label_per_item || empty($this->label))) {
            $out .= $this->wrap_with_multi_tools($form_element);
        } else {
            $out .= $form_element;
        }
        if ($render_label_after) {
            $out .= $label;
        }
        if (isset($this->description) && !empty($this->description) && $this->description_after_element) {
            $out .= sprintf('<div class="fm-item-description">%s</div>', $this->escape('description'));
        }
        $out .= '</div>';
        if ($is_proto) {
            $this->is_proto = false;
        }
        return $out;
    }