PHP Class Select2CustomFieldType

This class defines the select2 field type.

Field Definition Arguments

Field Type Specific Arguments

  • **is_multiple** - (optional, boolean) if this is set to true, the multiple attribute will be inserted into the field input tag, which enables the multiple selections for the user.
  • **options** - (optional, array) The options argument passed to the select2 method. For detaks, see https://select2.github.io/options.html
  • **callback** - (optional, array)
    • **search** - (optional, callable) Set a callback function that is triggered in the background when the user type something in the select input field expecting a list of suggested items will be displayed. - $aQueries - (array) an array holding the following arguments. - q - (string) the queried characters. - page - (string) the pagination number. When the result has too many items, it can be paginated. - field_id - (string) the field ID that calls the query. - section_id - (string) the section ID that calls the query. - $aFieldset - (array) the field definition array. The callback method is expected to return an array with the following structure: array( 'results' => array( array( 'id' => 224, //the value saved in the database. 'text' => 'The title of this item.' //The text displayed in the drop-down list. ), array( 'id' => 567, 'text' => 'The title of this item.' ), ... continues ... ), 'pagination' => array( // can be omitted 'more' => true, // (boolean) or false - whether the next paginated item exists or not. ) )
    • **new_tag** - (optional, callable) Set a callback function that is called when the user creates a new tag. - $aQueries - (array) an array holding the following arguments. - tag - (string) the tag name. - field_id - (string) the field ID that calls the query. - section_id - (string) the section ID that calls the query. - $aFieldset - (array) the field definition array. If this callback is set, the options -> tags argument will be automatically enabled. The callback method is expected to return an array with the following structure: array( 'id' => 78, // the value which will be stored in the database. 'text' => 'Tag Name', // the tag name gets displayed in the field. 'note' => 'A console message.' // (optional) A note displayed in the browser console. 'error' => 'An error massage.', // (optional) if this is set, an error message will be displayed. )
Since: 3.8.7
Inheritance: extends AdminPageFramework_FieldType_select
Show file Open project: michaeluno/admin-page-framework

Public Properties

Property Type Description
$aFieldTypeSlugs Defines the field type slugs used for this field type.

Protected Properties

Property Type Description
$aDefaultKeys Defines the default key-values of this field type settings.

Public Methods

Method Description
getField ( $aField ) : string Returns the output of the field type.
setUp ( ) Loads the field type necessary components.

Protected Methods

Method Description
construct ( )
doOnFieldRegistration ( $aFieldset ) Callks back the callback function if it is set.
getEnqueuingScripts ( ) : array Returns an array holding the urls of enqueuing scripts.
getEnqueuingStyles ( ) : array
getScripts ( ) Returns the field type specific JavaScript script.
getStyles ( ) Returns the field type specific CSS rules.

Private Methods

Method Description
_getAjaxCallback ( $aRequest, $aFieldset ) : boolean | callable
_getAttributesUpdatedForAJAX ( $aField ) : array For AJAX enabled fields, the stored field data structure becomes different.
_getCamelCaseToDashed ( $sString ) : string
_getChildInputByKey ( $sKey, $aField ) : string
_getSelect2OptionsFormatted ( $aOptions, $aField ) : array
_shouldProceedToAjaxRequest ( $aRequest, $aFieldset ) : boolean

Method Details

construct() protected method

protected construct ( )

doOnFieldRegistration() protected method

Called when the field type is registered.
protected doOnFieldRegistration ( $aFieldset )

getEnqueuingScripts() protected method

Returns an array holding the urls of enqueuing scripts.
protected getEnqueuingScripts ( ) : array
return array

getEnqueuingStyles() protected method

protected getEnqueuingStyles ( ) : array
return array

getField() public method

Returns the output of the field type.
public getField ( $aField ) : string
return string

getScripts() protected method

Returns the field type specific JavaScript script.
protected getScripts ( )

getStyles() protected method

Returns the field type specific CSS rules.
protected getStyles ( )

setUp() public method

Loads the field type necessary components.
public setUp ( )

Property Details

$aDefaultKeys protected property

Defines the default key-values of this field type settings.
protected $aDefaultKeys

$aFieldTypeSlugs public property

Defines the field type slugs used for this field type.
public $aFieldTypeSlugs