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 | ||
| 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
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
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 67
__construct(string|Stringable|null $caption = null)
No description
at line 82
BaseControl
setCaption(string|Stringable|null $caption)
No description
at line 89
string|Stringable|null
getCaption()
No description
at line 99
Form|null
getForm(bool $throw = true)
Returns form.
at line 108
void
loadHttpData()
Loads HTTP data.
at line 117
protected mixed
getHttpData(int $type, string|null $htmlTail = null)
Returns submitted HTTP value for this control.
at line 126
string
getHtmlName()
Returns HTML name of control.
at line 136
Control
setValue(mixed $value)
| internal |
No description
at line 143
mixed
getValue()
No description
at line 152
bool
isFilled()
Is control filled?
at line 162
BaseControl
setDefaultValue(mixed $value)
Sets the default value. Has no effect on submitted or disabled controls.
at line 176
BaseControl
setDisabled(bool $state = true)
Disables or enables control.
at line 192
bool
isDisabled()
Is control disabled?
at line 201
BaseControl
setOmitted(bool $state = true)
Excludes or includes the control value from $form->getValues() result.
at line 211
bool
isOmitted()
Is control value excluded from $form->getValues() result?
at line 223
Html|string
getControl()
Generates control's HTML element.
at line 240
Html|string|null
getLabel(string|Stringable|null $caption = null)
Generates label's HTML element.
at line 251
Html|null
getControlPart()
No description
at line 258
Html|null
getLabelPart()
No description
at line 268
Html
getControlPrototype()
Returns control's HTML element template.
at line 277
Html
getLabelPrototype()
Returns label's HTML element template.
at line 286
BaseControl
setHtmlId(string|bool|null $id)
Changes control's HTML id.
at line 296
string|bool|null
getHtmlId()
Returns control's HTML id.
at line 313
BaseControl
setHtmlAttribute(string $name, mixed $value = true)
Changes control's HTML attribute.
at line 330
BaseControl
setAttribute(string $name, mixed $value = true)
No description
at line 341
BaseControl
setTranslator(Translator|null $translator)
No description
at line 351
Translator|null
getTranslator()
Returns the translator, or inherits it from the form when not explicitly set.
at line 366
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 388
BaseControl
addRule(callable|string $validator, string|Stringable|null $errorMessage = null, mixed $arg = null)
Adds a validation rule.
at line 403
Rules
addCondition(callable|string|bool $validator, mixed $value = null)
Adds a validation condition and returns a new branch.
at line 413
Rules
addConditionOn(Control $control, callable|string $validator, mixed $value = null)
Adds a validation condition based on another control and returns a new branch.
at line 423
BaseControl
addFilter(callable $filter)
Adds an input filter callback.
at line 430
Rules
getRules()
No description
at line 439
BaseControl
setRequired(string|Stringable|bool $value = true)
Makes control mandatory.
at line 449
bool
isRequired()
Is control mandatory?
at line 458
void
validate()
Performs server-side validation against all rules.
at line 472
void
addError(string|Stringable $message, bool $translate = true)
Adds error message to the list.
at line 481
string|null
getError()
Returns all control errors joined into one string, or null if there are no errors.
at line 491
array
getErrors()
Returns all unique validation errors for this control.
at line 497
bool
hasErrors()
No description
at line 503
void
cleanErrors()
No description
at line 515
BaseControl
setOption(string $key, mixed $value)
Sets a rendering or user-specific option (e.g. 'description', 'class', 'id').
at line 530
mixed
getOption(string $key)
Returns a rendering or user-specific option value.
at line 540
array
getOptions()
Returns all rendering and user-specific options.
at line 550
mixed
__call(string $name, array $args)
No description
at line 566
static void
extensionMethod(string $name, callable $callback)
No description