Control: Section Open Close - 10quality/wpmvc-addon-administrator GitHub Wiki

Controls used as field types to open and close a fieldset (fields section) wrapper.

Section and separator

It is recommended to use fieldsets (section) because the spacing between fields will be reduced.

Usage

This control doesn't need a specific id, so you can use uniqid() as field ID, see an example:

// Namespace and use statement...

class Settings extends Model
{
    // Class properties...

    protected function init()
    {
        // Other properties...

        $this->tabs = [
            'tab_id' => [
                'fields' => [

                    uniqid() => [
                        'type' => 'section_open',

                        // Optional. Default: Empty
                        'title' => __( 'Section title', 'my-domain' ),

                        // Optional. Default: Empty
                        'description' => __( 'Section description', 'my-domain' ),
                    ],

                    'field_id1' => [...],
                    'field_id2' => [...],

                    uniqid() => [
                       'type' => 'section_close',
                    ],
                    // Other fields...
                ],
            ],
        ];
    }
}

Auto close

The add-on is intelligent enough to catch open sections without defined closure and will close them automatically.

// Namespace and use statement...

class Settings extends Model
{
    // Class properties...

    protected function init()
    {
        // Other properties...

        $this->tabs = [
            'tab_id' => [
                'fields' => [

                    uniqid() => [
                        'type' => 'section_open',
                    ],
                    'field_id1' => [...],
                    'field_id2' => [...],

                    // <=== ADD-ON will close the section here
                ],
            ],
        ];
    }
}

Separator

Use control type section_separator to render a line between fieldsets (sections), see an example:

// Namespace and use statement...

class Settings extends Model
{
    // Class properties...

    protected function init()
    {
        // Other properties...

        $this->tabs = [
            'tab_id' => [
                'fields' => [

                    uniqid() => [
                        'type' => 'section_open',
                        'title' => __( 'Section 1', 'my-domain' ),
                    ],

                    'field_id1' => [...],
                    'field_id2' => [...],

                    uniqid() => [
                       'type' => 'section_separator',
                    ],

                    uniqid() => [
                        'type' => 'section_open',
                        'title' => __( 'Section 2', 'my-domain' ),
                    ],

                    // Other fields...
                ],
            ],
        ];
    }
}