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
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 69
__construct(string|Stringable|null $caption = null)
No description
at line 84
BaseControl
setCaption(string|Stringable|null $caption)
No description
at line 91
string|Stringable|null
getCaption()
No description
at line 101
Form|null
getForm(bool $throw = true)
Returns form.
at line 110
void
loadHttpData()
Loads HTTP data.
at line 119
protected mixed
getHttpData(int $type, string|null $htmlTail = null)
Returns submitted HTTP value for this control.
at line 128
string
getHtmlName()
Returns HTML name of control.
at line 141
Control
setValue(mixed $value)
| internal |
No description
at line 149
mixed
getValue()
No description
at line 158
bool
isFilled()
Is control filled?
at line 169
BaseControl
setDefaultValue(mixed $value)
Sets the default value. Has no effect on submitted or disabled controls.
at line 184
BaseControl
setDisabled(bool $state = true)
Disables or enables control.
at line 200
bool
isDisabled()
Is control disabled?
at line 209
BaseControl
setOmitted(bool $state = true)
Excludes or includes the control value from $form->getValues() result.
at line 219
bool
isOmitted()
Is control value excluded from $form->getValues() result?
at line 232
Html|string
getControl()
Generates control's HTML element.
at line 250
Html|string|null
getLabel(string|Stringable|null $caption = null)
Generates label's HTML element.
at line 261
Html|null
getControlPart()
No description
at line 268
Html|null
getLabelPart()
No description
at line 278
Html
getControlPrototype()
Returns control's HTML element template.
at line 287
Html
getLabelPrototype()
Returns label's HTML element template.
at line 296
BaseControl
setHtmlId(string|bool|null $id)
Changes control's HTML id.
at line 306
string|bool|null
getHtmlId()
Returns control's HTML id.
at line 323
BaseControl
setHtmlAttribute(string $name, mixed $value = true)
Changes control's HTML attribute.
at line 343
BaseControl
setAttribute(string $name, mixed $value = true)
deprecated
deprecated
No description
at line 352
BaseControl
setTranslator(Translator|null $translator)
No description
at line 362
Translator|null
getTranslator()
Returns the translator, or inherits it from the form when not explicitly set.
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.
at line 400
BaseControl
addRule(callable|string $validator, string|Stringable|null $errorMessage = null, mixed $arg = null)
Adds a validation rule.
at line 414
Rules
addCondition($validator, mixed $value = null)
Adds a validation condition and returns a new branch.
at line 424
Rules
addConditionOn(Control $control, $validator, mixed $value = null)
Adds a validation condition based on another control and returns a new branch.
at line 434
BaseControl
addFilter(callable $filter)
Adds an input filter callback.
at line 441
Rules
getRules()
No description
at line 450
BaseControl
setRequired(string|Stringable|bool $value = true)
Makes control mandatory.
at line 460
bool
isRequired()
Is control mandatory?
at line 469
void
validate()
Performs server-side validation against all rules.
at line 483
void
addError(string|Stringable $message, bool $translate = true)
Adds error message to the list.
at line 492
string|null
getError()
Returns all control errors joined into one string, or null if there are no errors.
at line 502
array
getErrors()
Returns all unique validation errors for this control.
at line 508
bool
hasErrors()
No description
at line 514
void
cleanErrors()
No description
at line 526
BaseControl
setOption(string $key, mixed $value)
Sets a rendering or user-specific option (e.g. 'description', 'class', 'id').
at line 541
mixed
getOption(string $key)
Returns a rendering or user-specific option value.
at line 551
array
getOptions()
Returns all rendering and user-specific options.
at line 564
mixed
__call(string $name, array $args)
No description
at line 580
static void
extensionMethod(string $name, callable $callback)
No description