PHP Class Fieldmanager_Group, vip-mu-plugins-public

Groups shouldn't just be thought of as a top-level collection of fields (like a meta box). Groups can be infinitely nested, they can be used to create tabbed interfaces, and so on. Groups submit data as nested arrays.
Inheritance: extends Fieldmanager_Field
ファイルを表示 Open project: Automattic/vip-mu-plugins-public Class Usage Examples

Public Properties

Property Type Description
$add_to_prefix boolean If false, Fieldmanager will not check for collisions among the meta keys created for this group's fields and other registered fields.
$children Fieldmanager_Field[] Children elements of this group. Not much point in creating an empty group.
$collapsed boolean If true, this group is collapsed by default.
$collapsible boolean If true, this group can be collapsed by clicking its header.
$field_class string Override field class
$group_is_empty callable | null Function that tells whether the group is empty or not. Gets an array of form values.
$has_unserialized_descendants boolean This field is set based on its descendants, but you can deliberately set it yourself if your situation is one where this cannot be determined automatically (for instance, where descendants are added after the group has been constructed).
$label_element string Override label element
$label_format string If specified, $label_format combined with $label_token will override $label, but only if $(label).find(label_token).val() is not null.
$label_macro array Label macro is a more convenient shortcut to label_format and label_token. The first element of the two-element array is the title with a placeholder (%s), and the second element is simply the name of the child element to pull from, e.g.: array( 'Section: %s', 'section_title' )
$label_token string CSS selector to an element to get the token for the label format
$persist_active_tab boolean Persist the active tab on the group between sessions
$tab_limit integer How many tabs, maximum?
$tabbed boolean | string Use tabbed groups. Currently supports "horizontal" or "vertical". Default is false, which means that the group will not be tabbed.

Protected Properties

Property Type Description
$child_count boolean Iterator value for how many children we have rendered.

Public Methods

Method Description
__construct ( $label = '', $options = [] ) Constructor; add CSS if we're looking at a tabbed view
add_child ( Fieldmanager_Field $child ) : void Add a child element to this group.
form_element ( mixed $value = NULL ) Render the element, iterating over children and calling their form_element() functions.
get_element_label ( array $classes = [] ) : string Get an HTML label for this element.
get_extra_element_classes ( ) : array Maybe add the collapsible class for groups
presave ( $values, $current_values = [] ) : mixed[] Presave override for groups which dispatches to child presave_all methods.
wrap_with_multi_tools ( string $html, $classes = [] ) : string Groups have their own drag and remove tools in the label.

Protected Methods

Method Description
add_meta_boxes_to_remove ( &$meta_boxes_to_remove ) : array Helper function to get the list of default meta boxes to remove.

Method Details

__construct() public method

Constructor; add CSS if we're looking at a tabbed view
public __construct ( $label = '', $options = [] )

add_child() public method

Add a child element to this group.
public add_child ( Fieldmanager_Field $child ) : void
$child Fieldmanager_Field
return void

add_meta_boxes_to_remove() protected method

For Fieldmanager_Group, iterate over all children to see if they have meta boxes to remove. If $remove_default_meta_boxes is true for this group, set all children to also remove any default meta boxes if applicable.
protected add_meta_boxes_to_remove ( &$meta_boxes_to_remove ) : array
$meta_boxes_to_remove the array of meta boxes to remove
return array list of meta boxes to remove

form_element() public method

Render the element, iterating over children and calling their form_element() functions.
public form_element ( mixed $value = NULL )
$value mixed

get_element_label() public method

Get an HTML label for this element.
public get_element_label ( array $classes = [] ) : string
$classes array extra CSS classes.
return string HTML label.

get_extra_element_classes() public method

Maybe add the collapsible class for groups
public get_extra_element_classes ( ) : array
return array

presave() public method

Presave override for groups which dispatches to child presave_all methods.
public presave ( $values, $current_values = [] ) : mixed[]
return mixed[] values

wrap_with_multi_tools() public method

Groups have their own drag and remove tools in the label.
public wrap_with_multi_tools ( string $html, $classes = [] ) : string
$html string
return string

Property Details

$add_to_prefix public_oe property

If false, Fieldmanager will not check for collisions among the meta keys created for this group's fields and other registered fields.
public bool $add_to_prefix
return boolean

$child_count protected_oe property

Iterator value for how many children we have rendered.
protected bool $child_count
return boolean

$children public_oe property

Children elements of this group. Not much point in creating an empty group.
public Fieldmanager_Field[] $children
return Fieldmanager_Field[]

$collapsed public_oe property

If true, this group is collapsed by default.
public bool $collapsed
return boolean

$collapsible public_oe property

If true, this group can be collapsed by clicking its header.
public bool $collapsible
return boolean

$field_class public_oe property

Override field class
public string $field_class
return string

$group_is_empty public_oe property

Function that tells whether the group is empty or not. Gets an array of form values.
public callable|null $group_is_empty
return callable | null

$has_unserialized_descendants public_oe property

This field is set based on its descendants, but you can deliberately set it yourself if your situation is one where this cannot be determined automatically (for instance, where descendants are added after the group has been constructed).
public bool $has_unserialized_descendants
return boolean

$label_element public_oe property

Override label element
public string $label_element
return string

$label_format public_oe property

If specified, $label_format combined with $label_token will override $label, but only if $(label).find(label_token).val() is not null.
public string $label_format
return string

$label_macro public_oe property

Label macro is a more convenient shortcut to label_format and label_token. The first element of the two-element array is the title with a placeholder (%s), and the second element is simply the name of the child element to pull from, e.g.: array( 'Section: %s', 'section_title' )
public array $label_macro
return array

$label_token public_oe property

CSS selector to an element to get the token for the label format
public string $label_token
return string

$persist_active_tab public_oe property

Persist the active tab on the group between sessions
public bool $persist_active_tab
return boolean

$tab_limit public_oe property

How many tabs, maximum?
public int $tab_limit
return integer

$tabbed public_oe property

Use tabbed groups. Currently supports "horizontal" or "vertical". Default is false, which means that the group will not be tabbed.
public bool|string $tabbed
return boolean | string