BaseControl
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
No description
No description
No description
Returns form.
Loads HTTP data.
Returns submitted HTTP value for this control.
Returns HTML name of control.
No description
Is control filled?
Sets the default value. Has no effect on submitted or disabled controls.
Disables or enables control.
Is control disabled?
Excludes or includes the control value from $form->getValues() result.
Is control value excluded from $form->getValues() result?
Generates control's HTML element.
Generates label's HTML element.
No description
No description
Returns control's HTML element template.
Returns label's HTML element template.
Changes control's HTML id.
Returns control's HTML id.
Changes control's HTML attribute.
No description
Returns the translator, or inherits it from the form when not explicitly set.
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.
Adds a validation rule.
Adds a validation condition and returns a new branch.
Adds a validation condition based on another control and returns a new branch.
Adds an input filter callback.
Makes control mandatory.
Is control mandatory?
Performs server-side validation against all rules.
Adds error message to the list.
Returns all control errors joined into one string, or null if there are no errors.
Returns all unique validation errors for this control.
No description
No description
Sets a rendering or user-specific option (e.g. 'description', 'class', 'id').
Returns a rendering or user-specific option value.
Returns all rendering and user-specific options.
No description
No description
Details
at line 66
__construct(string|Stringable|null $caption = null)
No description
at line 81
BaseControl
setCaption(string|Stringable|null $caption)
No description
at line 88
string|Stringable|null
getCaption()
No description
at line 98
Form|null
getForm(bool $throw = true)
Returns form.
at line 107
void
loadHttpData()
Loads HTTP data.
at line 116
protected mixed
getHttpData(int $type, string|null $htmlTail = null)
Returns submitted HTTP value for this control.
at line 125
string
getHtmlName()
Returns HTML name of control.
at line 138
Control
setValue(mixed $value)
| internal |
No description
at line 146
mixed
getValue()
No description
at line 155
bool
isFilled()
Is control filled?
at line 166
BaseControl
setDefaultValue(mixed $value)
Sets the default value. Has no effect on submitted or disabled controls.
at line 181
BaseControl
setDisabled(bool $state = true)
Disables or enables control.
at line 197
bool
isDisabled()
Is control disabled?
at line 206
BaseControl
setOmitted(bool $state = true)
Excludes or includes the control value from $form->getValues() result.
at line 216
bool
isOmitted()
Is control value excluded from $form->getValues() result?
at line 229
Html|string
getControl()
Generates control's HTML element.
at line 247
Html|string|null
getLabel(string|Stringable|null $caption = null)
Generates label's HTML element.
at line 258
Html|null
getControlPart()
No description
at line 265
Html|null
getLabelPart()
No description
at line 275
Html
getControlPrototype()
Returns control's HTML element template.
at line 284
Html
getLabelPrototype()
Returns label's HTML element template.
at line 293
BaseControl
setHtmlId(string|bool|null $id)
Changes control's HTML id.
at line 303
string|bool|null
getHtmlId()
Returns control's HTML id.
at line 320
BaseControl
setHtmlAttribute(string $name, mixed $value = true)
Changes control's HTML attribute.
at line 340
BaseControl
setAttribute(string $name, mixed $value = true)
deprecated
deprecated
No description
at line 349
BaseControl
setTranslator(Translator|null $translator)
No description
at line 359
Translator|null
getTranslator()
Returns the translator, or inherits it from the form when not explicitly set.
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.
at line 397
BaseControl
addRule(callable|string $validator, string|Stringable|null $errorMessage = null, mixed $arg = null)
Adds a validation rule.
at line 411
Rules
addCondition($validator, mixed $value = null)
Adds a validation condition and returns a new branch.
at line 421
Rules
addConditionOn(Control $control, $validator, mixed $value = null)
Adds a validation condition based on another control and returns a new branch.
at line 431
BaseControl
addFilter(callable $filter)
Adds an input filter callback.
at line 438
Rules
getRules()
No description
at line 447
BaseControl
setRequired(string|Stringable|bool $value = true)
Makes control mandatory.
at line 457
bool
isRequired()
Is control mandatory?
at line 466
void
validate()
Performs server-side validation against all rules.
at line 480
void
addError(string|Stringable $message, bool $translate = true)
Adds error message to the list.
at line 489
string|null
getError()
Returns all control errors joined into one string, or null if there are no errors.
at line 499
array
getErrors()
Returns all unique validation errors for this control.
at line 505
bool
hasErrors()
No description
at line 511
void
cleanErrors()
No description
at line 523
BaseControl
setOption(string $key, mixed $value)
Sets a rendering or user-specific option (e.g. 'description', 'class', 'id').
at line 538
mixed
getOption(string $key)
Returns a rendering or user-specific option value.
at line 552
array
getOptions()
Returns all rendering and user-specific options.
at line 562
__call(string $name, array $args)
No description
at line 578
static void
extensionMethod(string $name, callable $callback)
No description