abstract class BaseControl extends Component implements Control

Base implementation for form controls with HTML rendering, validation, translation, and option support.

Properties

static $idMask
mixed $value
Html read-only $control
Html read-only $label
bool $disabled
string|bool|null $htmlId
string|Stringable $caption
bool $omitted
bool $required
Form read-only $form
string read-only $htmlName
Html read-only $controlPrototype
Html read-only $labelPrototype
bool read-only $filled
string[] read-only $errors
array<string,mixed> read-only $options
string read-only $error

Methods

__construct(string|Stringable|null $caption = null)

No description

setCaption(string|Stringable|null $caption)

No description

string|Stringable|null
getCaption()

No description

Form|null
getForm(bool $throw = true)

Returns form.

void
loadHttpData()

Loads HTTP data.

mixed
getHttpData(int $type, string|null $htmlTail = null)

Returns submitted HTTP value for this control.

string
getHtmlName()

Returns HTML name of control.

setValue(mixed $value)

No description

mixed
getValue()

No description

bool
isFilled()

Is control filled?

setDefaultValue(mixed $value)

Sets the default value. Has no effect on submitted or disabled controls.

setDisabled(bool $state = true)

Disables or enables control.

bool
isDisabled()

Is control disabled?

setOmitted(bool $state = true)

Excludes or includes the control value from $form->getValues() result.

bool
isOmitted()

Is control value excluded from $form->getValues() result?

Html|string
getControl()

Generates control's HTML element.

Html|string|null
getLabel(string|Stringable|null $caption = null)

Generates label's HTML element.

Html|null
getControlPart()

No description

Html|null
getLabelPart()

No description

Html
getControlPrototype()

Returns control's HTML element template.

Html
getLabelPrototype()

Returns label's HTML element template.

setHtmlId(string|bool|null $id)

Changes control's HTML id.

string|bool|null
getHtmlId()

Returns control's HTML id.

setHtmlAttribute(string $name, mixed $value = true)

Changes control's HTML attribute.

setAttribute(string $name, mixed $value = true) deprecated

No description

setTranslator(Translator|null $translator)

No description

Translator|null
getTranslator()

Returns the translator, or inherits it from the form when not explicitly set.

mixed
translate(mixed $value, mixed ...$parameters)

Translates a string or array of strings using the configured translator, or returns the value unchanged if no translator is set or the value is HtmlStringable.

addRule(callable|string $validator, string|Stringable|null $errorMessage = null, mixed $arg = null)

Adds a validation rule.

addCondition($validator, mixed $value = null)

Adds a validation condition and returns a new branch.

addConditionOn(Control $control, $validator, mixed $value = null)

Adds a validation condition based on another control and returns a new branch.

addFilter(callable $filter)

Adds an input filter callback.

getRules()

No description

setRequired(string|Stringable|bool $value = true)

Makes control mandatory.

bool
isRequired()

Is control mandatory?

void
validate()

Performs server-side validation against all rules.

void
addError(string|Stringable $message, bool $translate = true)

Adds error message to the list.

string|null
getError()

Returns all control errors joined into one string, or null if there are no errors.

array
getErrors()

Returns all unique validation errors for this control.

bool
hasErrors()

No description

void
cleanErrors()

No description

setOption(string $key, mixed $value)

Sets a rendering or user-specific option (e.g. 'description', 'class', 'id').

mixed
getOption(string $key)

Returns a rendering or user-specific option value.

array
getOptions()

Returns all rendering and user-specific options.

__call(string $name, array $args)

No description

static void
extensionMethod(string $name, callable $callback)

No description

Details

at line 66
__construct(string|Stringable|null $caption = null)

No description

Parameters

string|Stringable|null $caption

at line 81
BaseControl setCaption(string|Stringable|null $caption)

No description

Parameters

string|Stringable|null $caption

Return Value

BaseControl

at line 88
string|Stringable|null getCaption()

No description

Return Value

string|Stringable|null

at line 98
Form|null getForm(bool $throw = true)

Returns form.

Parameters

bool $throw

Return Value

Form|null

at line 107
void loadHttpData()

Loads HTTP data.

Return Value

void

at line 116
protected mixed getHttpData(int $type, string|null $htmlTail = null)

Returns submitted HTTP value for this control.

Parameters

int $type
string|null $htmlTail

Return Value

mixed

at line 125
string getHtmlName()

Returns HTML name of control.

Return Value

string

at line 138
Control setValue(mixed $value)

internal  
 

No description

Parameters

mixed $value

Return Value

Control

at line 146
mixed getValue()

No description

Return Value

mixed

at line 155
bool isFilled()

Is control filled?

Return Value

bool

at line 166
BaseControl setDefaultValue(mixed $value)

Sets the default value. Has no effect on submitted or disabled controls.

Parameters

mixed $value

Return Value

BaseControl

at line 181
BaseControl setDisabled(bool $state = true)

Disables or enables control.

Parameters

bool $state

Return Value

BaseControl

at line 197
bool isDisabled()

Is control disabled?

Return Value

bool

at line 206
BaseControl setOmitted(bool $state = true)

Excludes or includes the control value from $form->getValues() result.

Parameters

bool $state

Return Value

BaseControl

at line 216
bool isOmitted()

Is control value excluded from $form->getValues() result?

Return Value

bool

at line 229
Html|string getControl()

Generates control's HTML element.

Return Value

Html|string

at line 247
Html|string|null getLabel(string|Stringable|null $caption = null)

Generates label's HTML element.

Parameters

string|Stringable|null $caption

Return Value

Html|string|null

at line 258
Html|null getControlPart()

No description

Return Value

Html|null

at line 265
Html|null getLabelPart()

No description

Return Value

Html|null

at line 275
Html getControlPrototype()

Returns control's HTML element template.

Return Value

Html

at line 284
Html getLabelPrototype()

Returns label's HTML element template.

Return Value

Html

at line 293
BaseControl setHtmlId(string|bool|null $id)

Changes control's HTML id.

Parameters

string|bool|null $id

Return Value

BaseControl

at line 303
string|bool|null getHtmlId()

Returns control's HTML id.

Return Value

string|bool|null

at line 320
BaseControl setHtmlAttribute(string $name, mixed $value = true)

Changes control's HTML attribute.

Parameters

string $name
mixed $value

Return Value

BaseControl

at line 340
BaseControl setAttribute(string $name, mixed $value = true) deprecated

deprecated use setHtmlAttribute()

No description

Parameters

string $name
mixed $value

Return Value

BaseControl

at line 349
BaseControl setTranslator(Translator|null $translator)

No description

Parameters

Translator|null $translator

Return Value

BaseControl

at line 359
Translator|null getTranslator()

Returns the translator, or inherits it from the form when not explicitly set.

Return Value

Translator|null

at line 374
mixed translate(mixed $value, mixed ...$parameters)

Translates a string or array of strings using the configured translator, or returns the value unchanged if no translator is set or the value is HtmlStringable.

Parameters

mixed $value
mixed ...$parameters

Return Value

mixed

at line 397
BaseControl addRule(callable|string $validator, string|Stringable|null $errorMessage = null, mixed $arg = null)

Adds a validation rule.

Parameters

callable|string $validator
string|Stringable|null $errorMessage
mixed $arg

Return Value

BaseControl

at line 411
Rules addCondition($validator, mixed $value = null)

Adds a validation condition and returns a new branch.

Parameters

$validator
mixed $value

Return Value

Rules

at line 421
Rules addConditionOn(Control $control, $validator, mixed $value = null)

Adds a validation condition based on another control and returns a new branch.

Parameters

Control $control
$validator
mixed $value

Return Value

Rules

at line 431
BaseControl addFilter(callable $filter)

Adds an input filter callback.

Parameters

callable $filter

Return Value

BaseControl

at line 438
Rules getRules()

No description

Return Value

Rules

at line 447
BaseControl setRequired(string|Stringable|bool $value = true)

Makes control mandatory.

Parameters

string|Stringable|bool $value

Return Value

BaseControl

at line 457
bool isRequired()

Is control mandatory?

Return Value

bool

at line 466
void validate()

Performs server-side validation against all rules.

Return Value

void

at line 480
void addError(string|Stringable $message, bool $translate = true)

Adds error message to the list.

Parameters

string|Stringable $message
bool $translate

Return Value

void

at line 489
string|null getError()

Returns all control errors joined into one string, or null if there are no errors.

Return Value

string|null

at line 499
array getErrors()

Returns all unique validation errors for this control.

Return Value

array

at line 505
bool hasErrors()

No description

Return Value

bool

at line 511
void cleanErrors()

No description

Return Value

void

at line 523
BaseControl setOption(string $key, mixed $value)

Sets a rendering or user-specific option (e.g. 'description', 'class', 'id').

Parameters

string $key
mixed $value

Return Value

BaseControl

at line 538
mixed getOption(string $key)

Returns a rendering or user-specific option value.

Parameters

string $key

Return Value

mixed

at line 552
array getOptions()

Returns all rendering and user-specific options.

Return Value

array

at line 562
__call(string $name, array $args)

No description

Parameters

string $name
array $args

at line 578
static void extensionMethod(string $name, callable $callback)

No description

Parameters

string $name
callable $callback

Return Value

void