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
bool $required
string read-only $name
Form read-only $form
Html read-only $controlPrototype
Html read-only $labelPrototype
string[] read-only $errors
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.

mixed
__call(string $name, array $args)

No description

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

No description

Details

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

No description

Parameters

string|Stringable|null $caption

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

No description

Parameters

string|Stringable|null $caption

Return Value

BaseControl

at line 91
string|Stringable|null getCaption()

No description

Return Value

string|Stringable|null

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

Returns form.

Parameters

bool $throw

Return Value

Form|null

at line 110
void loadHttpData()

Loads HTTP data.

Return Value

void

at line 119
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 128
string getHtmlName()

Returns HTML name of control.

Return Value

string

at line 141
Control setValue(mixed $value)

internal  
 

No description

Parameters

mixed $value

Return Value

Control

at line 149
mixed getValue()

No description

Return Value

mixed

at line 158
bool isFilled()

Is control filled?

Return Value

bool

at line 169
BaseControl setDefaultValue(mixed $value)

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

Parameters

mixed $value

Return Value

BaseControl

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

Disables or enables control.

Parameters

bool $state

Return Value

BaseControl

at line 200
bool isDisabled()

Is control disabled?

Return Value

bool

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

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

Parameters

bool $state

Return Value

BaseControl

at line 219
bool isOmitted()

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

Return Value

bool

at line 232
Html|string getControl()

Generates control's HTML element.

Return Value

Html|string

at line 250
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 261
Html|null getControlPart()

No description

Return Value

Html|null

at line 268
Html|null getLabelPart()

No description

Return Value

Html|null

at line 278
Html getControlPrototype()

Returns control's HTML element template.

Return Value

Html

at line 287
Html getLabelPrototype()

Returns label's HTML element template.

Return Value

Html

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

Changes control's HTML id.

Parameters

string|bool|null $id

Return Value

BaseControl

at line 306
string|bool|null getHtmlId()

Returns control's HTML id.

Return Value

string|bool|null

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

Changes control's HTML attribute.

Parameters

string $name
mixed $value

Return Value

BaseControl

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

deprecated use setHtmlAttribute()

No description

Parameters

string $name
mixed $value

Return Value

BaseControl

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

No description

Parameters

Translator|null $translator

Return Value

BaseControl

at line 362
Translator|null getTranslator()

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

Return Value

Translator|null

at line 377
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 400
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 414
Rules addCondition($validator, mixed $value = null)

Adds a validation condition and returns a new branch.

Parameters

$validator
mixed $value

Return Value

Rules

at line 424
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 434
BaseControl addFilter(callable $filter)

Adds an input filter callback.

Parameters

callable $filter

Return Value

BaseControl

at line 441
Rules getRules()

No description

Return Value

Rules

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

Makes control mandatory.

Parameters

string|Stringable|bool $value

Return Value

BaseControl

at line 460
bool isRequired()

Is control mandatory?

Return Value

bool

at line 469
void validate()

Performs server-side validation against all rules.

Return Value

void

at line 483
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 492
string|null getError()

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

Return Value

string|null

at line 502
array getErrors()

Returns all unique validation errors for this control.

Return Value

array

at line 508
bool hasErrors()

No description

Return Value

bool

at line 514
void cleanErrors()

No description

Return Value

void

at line 526
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 541
mixed getOption(string $key)

Returns a rendering or user-specific option value.

Parameters

string $key

Return Value

mixed

at line 551
array getOptions()

Returns all rendering and user-specific options.

Return Value

array

at line 564
mixed __call(string $name, array $args)

No description

Parameters

string $name
array $args

Return Value

mixed

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

No description

Parameters

string $name
callable $callback

Return Value

void

Traits

SmartObject