PHP Class Contao\Widget

The class functions as abstract parent class for all widget classes and provides methods to generate the form field markup and to validate the form field input. Usage: $widget = new TextField(); $widget->name = 'test'; $widget->label = 'Test'; if ($_POST) { $widget->validate(); if (!$widget->hasErrors()) { echo $widget->value; } }
Inheritance: extends contao\BaseTemplate
Afficher le fichier Open project: contao/core-bundle Class Usage Examples

Protected Properties

Свойство Type Description
$arrAttributes array Attributes
$arrConfiguration array Configuration
$arrErrors array Errors
$arrOptions array Options
$blnForAttribute boolean For attribute indicator
$blnSubmitInput boolean Submit indicator
$objDca object Data container
$strClass string CSS class
$strId integer Id
$strLabel string Label
$strName string Name
$strPrefix string CSS class prefix
$strWizard string Wizard
$varValue mixed Value

Méthodes publiques

Méthode Description
__construct ( array $arrAttributes = null ) Initialize the object
__get ( string $strKey ) : string Return an object property
__isset ( string $strKey ) : boolean Check whether an object property exists
__set ( string $strKey, mixed $varValue ) Set an object property
addAttribute ( string $strName, mixed $varValue ) Add an attribute
addAttributes ( array $arrAttributes ) Take an associative array and add it to the object's attributes
addError ( string $strError ) Add an error message
generate ( ) : string Generate the widget and return it as string
generateLabel ( ) : string Generate the label and return it as string
generateWithError ( boolean $blnSwitchOrder = false ) : string Generate the widget with error message and return it as string
getAttribute ( string $strKey ) : string Return a single attribute
getAttributes ( array $arrStrip = [] ) : string Return all attributes as string
getAttributesFromDca ( array $arrData, string $strName, mixed $varValue = null, string $strField = '', string $strTable = '', DataContainer | null $objDca = null ) : array Extract the Widget attributes from a Data Container array
getEmptyStringOrNull ( ) : string | integer | null Return either an empty string or null based on the SQL string
getEmptyStringOrNullByFieldType ( string $sql ) : string | null Return either an empty string or null based on the SQL string
getEmptyValue ( ) : string | integer | null Return the empty value based on the SQL string
getEmptyValueByFieldType ( string $sql ) : string | integer | null Return the empty value based on the SQL string
getErrorAsHTML ( integer $intIndex ) : string Return a particular error as HTML string
getErrorAsString ( integer $intIndex ) : string Return a particular error as string
getErrors ( ) : array Return the errors array
getErrorsAsString ( string $strSeparator = null ) : string Return all errors as string separated by a given separator
hasErrors ( ) : boolean Return true if the widget has errors
optionChecked ( string $strOption, mixed $varValues ) : string Return a "checked" attribute if the option is checked
optionSelected ( string $strOption, mixed $varValues ) : string Return a "selected" attribute if the option is selected
parse ( array $arrAttributes = null ) : string Parse the template file and return it as string
submitInput ( ) : boolean Return true if the widgets submits user input
validate ( ) Validate the user input and set the value

Méthodes protégées

Méthode Description
addSubmit ( ) : string Generate a submit button
getPost ( string $strKey ) : mixed Find and return a $_POST variable
isChecked ( array $arrOption ) : string Check whether an option is checked
isSelected ( array $arrOption ) : string Check whether an option is selected
isValidOption ( mixed $varInput ) : boolean Check whether an input is one of the given options
validator ( mixed $varInput ) : mixed Recursively validate an input variable

Method Details

__construct() public méthode

Initialize the object
public __construct ( array $arrAttributes = null )
$arrAttributes array An optional attributes array

__get() public méthode

Return an object property
public __get ( string $strKey ) : string
$strKey string The property name
Résultat string The property value

__isset() public méthode

Check whether an object property exists
public __isset ( string $strKey ) : boolean
$strKey string The property name
Résultat boolean True if the property exists

__set() public méthode

Set an object property
public __set ( string $strKey, mixed $varValue )
$strKey string The property name
$varValue mixed The property value

addAttribute() public méthode

Add an attribute
public addAttribute ( string $strName, mixed $varValue )
$strName string The attribute name
$varValue mixed The attribute value

addAttributes() public méthode

Take an associative array and add it to the object's attributes
public addAttributes ( array $arrAttributes )
$arrAttributes array An array of attributes

addError() public méthode

Add an error message
public addError ( string $strError )
$strError string The error message

addSubmit() protected méthode

Generate a submit button
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0.
protected addSubmit ( ) : string
Résultat string The submit button markup

generate() abstract public méthode

Generate the widget and return it as string
abstract public generate ( ) : string
Résultat string The widget markup

generateLabel() public méthode

Generate the label and return it as string
public generateLabel ( ) : string
Résultat string The label markup

generateWithError() public méthode

Generate the widget with error message and return it as string
public generateWithError ( boolean $blnSwitchOrder = false ) : string
$blnSwitchOrder boolean If true, the error message will be shown below the field
Résultat string The form field markup

getAttribute() public méthode

Return a single attribute
public getAttribute ( string $strKey ) : string
$strKey string The attribute name
Résultat string The attribute markup

getAttributes() public méthode

Return all attributes as string
public getAttributes ( array $arrStrip = [] ) : string
$arrStrip array An optional array with attributes to strip
Résultat string The attributes string

getAttributesFromDca() public static méthode

Extract the Widget attributes from a Data Container array
public static getAttributesFromDca ( array $arrData, string $strName, mixed $varValue = null, string $strField = '', string $strTable = '', DataContainer | null $objDca = null ) : array
$arrData array The field configuration array
$strName string The field name in the form
$varValue mixed The field value
$strField string The field name in the database
$strTable string The table name in the database
$objDca DataContainer | null An optional DataContainer object
Résultat array An attributes array that can be passed to a widget

getEmptyStringOrNull() public méthode

Return either an empty string or null based on the SQL string
public getEmptyStringOrNull ( ) : string | integer | null
Résultat string | integer | null The empty value

getEmptyStringOrNullByFieldType() public static méthode

Return either an empty string or null based on the SQL string
public static getEmptyStringOrNullByFieldType ( string $sql ) : string | null
$sql string The SQL string
Résultat string | null The empty string or null

getEmptyValue() public méthode

Return the empty value based on the SQL string
public getEmptyValue ( ) : string | integer | null
Résultat string | integer | null The empty value

getEmptyValueByFieldType() public static méthode

Return the empty value based on the SQL string
public static getEmptyValueByFieldType ( string $sql ) : string | integer | null
$sql string The SQL string
Résultat string | integer | null The empty value

getErrorAsHTML() public méthode

Return a particular error as HTML string
public getErrorAsHTML ( integer $intIndex ) : string
$intIndex integer The message index
Résultat string The HTML markup of the corresponding error message

getErrorAsString() public méthode

Return a particular error as string
public getErrorAsString ( integer $intIndex ) : string
$intIndex integer The message index
Résultat string The corresponding error message

getErrors() public méthode

Return the errors array
public getErrors ( ) : array
Résultat array An array of error messages

getErrorsAsString() public méthode

Return all errors as string separated by a given separator
public getErrorsAsString ( string $strSeparator = null ) : string
$strSeparator string An optional separator (defaults to "
")
Résultat string The error messages string

getPost() protected méthode

Find and return a $_POST variable
protected getPost ( string $strKey ) : mixed
$strKey string The variable name
Résultat mixed The variable value

hasErrors() public méthode

Return true if the widget has errors
public hasErrors ( ) : boolean
Résultat boolean True if there are errors

isChecked() protected méthode

Check whether an option is checked
protected isChecked ( array $arrOption ) : string
$arrOption array The options array
Résultat string The "checked" attribute or an empty string

isSelected() protected méthode

Check whether an option is selected
protected isSelected ( array $arrOption ) : string
$arrOption array The options array
Résultat string The "selected" attribute or an empty string

isValidOption() protected méthode

Check whether an input is one of the given options
protected isValidOption ( mixed $varInput ) : boolean
$varInput mixed The input string or array
Résultat boolean True if the selected option exists

optionChecked() public static méthode

Return a "checked" attribute if the option is checked
public static optionChecked ( string $strOption, mixed $varValues ) : string
$strOption string The option to check
$varValues mixed One or more values to check against
Résultat string The attribute or an empty string

optionSelected() public static méthode

Return a "selected" attribute if the option is selected
public static optionSelected ( string $strOption, mixed $varValues ) : string
$strOption string The option to check
$varValues mixed One or more values to check against
Résultat string The attribute or an empty string

parse() public méthode

Parse the template file and return it as string
public parse ( array $arrAttributes = null ) : string
$arrAttributes array An optional attributes array
Résultat string The template markup

submitInput() public méthode

Return true if the widgets submits user input
public submitInput ( ) : boolean
Résultat boolean True if the widget submits user input

validate() public méthode

Validate the user input and set the value
public validate ( )

validator() protected méthode

Recursively validate an input variable
protected validator ( mixed $varInput ) : mixed
$varInput mixed The user input
Résultat mixed The original or modified user input

Property Details

$arrAttributes protected_oe property

Attributes
protected array $arrAttributes
Résultat array

$arrConfiguration protected_oe property

Configuration
protected array $arrConfiguration
Résultat array

$arrErrors protected_oe property

Errors
protected array $arrErrors
Résultat array

$arrOptions protected_oe property

Options
protected array $arrOptions
Résultat array

$blnForAttribute protected_oe property

For attribute indicator
protected bool $blnForAttribute
Résultat boolean

$blnSubmitInput protected_oe property

Submit indicator
protected bool $blnSubmitInput
Résultat boolean

$objDca protected_oe property

Data container
protected object $objDca
Résultat object

$strClass protected_oe property

CSS class
protected string $strClass
Résultat string

$strId protected_oe property

Id
protected int $strId
Résultat integer

$strLabel protected_oe property

Label
protected string $strLabel
Résultat string

$strName protected_oe property

Name
protected string $strName
Résultat string

$strPrefix protected_oe property

CSS class prefix
protected string $strPrefix
Résultat string

$strWizard protected_oe property

Wizard
protected string $strWizard
Résultat string

$varValue protected_oe property

Value
protected mixed $varValue
Résultat mixed