public function form_element($value = NULL)
{
$out = '';
$tab_group = '';
$tab_group_submenu = '';
// We do not need the wrapper class for extra padding if no label is set for the group
if (isset($this->label) && !empty($this->label)) {
$out .= '<div class="fm-group-inner">';
}
// If the display output for this group is set to tabs, build the tab group for navigation
if ($this->tabbed) {
$tab_group = sprintf('<ul class="fm-tab-bar wp-tab-bar %s" id="%s-tabs">', $this->persist_active_tab ? 'fm-persist-active-tab' : '', esc_attr($this->get_element_id()));
}
// Produce HTML for each of the children
foreach ($this->children as $element) {
$element->parent = $this;
// If the display output for this group is set to tabs, add a tab for this child
if ($this->tabbed) {
// Set default classes to display the first tab content and hide others
$tab_classes = array('fm-tab');
$tab_classes[] = $this->child_count == 0 ? "wp-tab-active" : "hide-if-no-js";
// Generate output for the tab. Depends on whether or not there is a tab limit in place.
if ($this->tab_limit == 0 || $this->child_count < $this->tab_limit) {
$tab_group .= sprintf('<li class="%s"><a href="#%s-tab">%s</a></li>', esc_attr(implode(" ", $tab_classes)), esc_attr($element->get_element_id()), $element->escape('label'));
} else {
if ($this->tab_limit != 0 && $this->child_count >= $this->tab_limit) {
$submenu_item_classes = array('fm-submenu-item');
$submenu_item_link_class = "";
// Create the More tab when first hitting the tab limit
if ($this->child_count == $this->tab_limit) {
// Create the tab
$tab_group_submenu .= sprintf('<li class="fm-tab fm-has-submenu"><a href="#%s-tab">%s</a>', esc_attr($element->get_element_id()), esc_html__('More...', 'fieldmanager'));
// Start the submenu
$tab_group_submenu .= sprintf('<div class="fm-submenu" id="%s-submenu"><div class="fm-submenu-wrap fm-submenu-wrap"><ul>', esc_attr($this->get_element_id()));
// Make sure the first submenu item is designated
$submenu_item_classes[] = 'fm-first-item';
$submenu_item_link_class = 'class="fm-first-item"';
}
// Add this element to the More menu
$tab_group_submenu .= sprintf('<li class="%s"><a href="#%s-tab" %s>%s</a></li>', esc_attr(implode(' ', $submenu_item_classes)), esc_attr($element->get_element_id()), $submenu_item_link_class, $element->escape('label'));
}
}
// Ensure the child is aware it is tab content
$element->is_tab = TRUE;
}
// Get markup for the child element
$child_value = isset($value[$element->name]) ? $value[$element->name] : null;
// propagate editor state down the chain
if ($this->data_type) {
$element->data_type = $this->data_type;
}
if ($this->data_id) {
$element->data_id = $this->data_id;
}
$out .= $element->element_markup($child_value);
$this->child_count++;
}
// We do not need the wrapper class for extra padding if no label is set for the group
if (isset($this->label) && !empty($this->label)) {
$out .= '</div>';
}
// If the display output for this group is set to tabs, build the tab group for navigation
if ($this->tab_limit != 0 && $this->child_count >= $this->tab_limit) {
$tab_group_submenu .= '</ul></div></div></li>';
}
if ($this->tabbed) {
$tab_group .= $tab_group_submenu . '</ul>';
}
// Return the complete HTML
return $tab_group . $out;
}