Final Class Yiisoft\FormModel\FormModelInputData
| Inheritance | Yiisoft\FormModel\FormModelInputData |
|---|---|
| Implements | Yiisoft\Form\Field\Base\InputData\InputDataInterface |
Public Methods
Method Details
| public __construct( Yiisoft\FormModel\FormModelInterface $model, string $property ): mixed | ||
| $model | Yiisoft\FormModel\FormModelInterface | |
| $property | string | |
public function __construct(
private readonly FormModelInterface $model,
string $property,
) {
$this->property = new ParsedProperty($property);
}
| public getHint( ): string|null |
public function getHint(): ?string
{
return $this->model->getPropertyHint($this->getPropertyName());
}
Generates an appropriate input ID.
This method converts the result getName() into a valid input ID.
For example, if \Yiisoft\FormModel\getInputName() returns Post[content], this method will return post-content.
| public getId( ): string | ||
| return | string |
The generated input ID. |
|---|---|---|
| throws | InvalidArgumentException |
If the property name contains non-word characters. |
public function getId(): string
{
$name = $this->getName();
$name = mb_strtolower($name, 'UTF-8');
return str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $name);
}
| public getLabel( ): string|null |
public function getLabel(): ?string
{
return $this->model->getPropertyLabel($this->getPropertyName() . $this->property->suffix);
}
Generates an appropriate input name.
This method generates a name that can be used as the input name to collect user input. The name is generated
according to the form and the property names. For example, if the form name is Post
then the input name generated for the content property would be Post[content].
See \Yiisoft\FormModel\getPropertyName() for explanation of property expression.
| public getName( ): string | ||
| return | string |
The generated input name. |
|---|---|---|
| throws | InvalidArgumentException |
If the property name contains non-word characters or empty form name for tabular inputs. |
public function getName(): string
{
$formName = $this->model->getFormName();
if ($formName === '' && $this->property->prefix === '') {
return $this->property->raw;
}
if ($formName !== '') {
return sprintf(
'%s%s[%s]%s',
$formName,
$this->property->prefix,
$this->property->name,
$this->property->suffix,
);
}
throw new InvalidArgumentException('Form name cannot be empty for tabular inputs.');
}
| public getPlaceholder( ): string|null |
public function getPlaceholder(): ?string
{
$placeholder = $this->model->getPropertyPlaceholder($this->getPropertyName());
return $placeholder === '' ? null : $placeholder;
}
| public getValidationErrors( ): array |
public function getValidationErrors(): array
{
/** @psalm-var list<string> */
return $this->model->isValidated()
? $this->model->getValidationResult()->getPropertyErrorMessagesByPath($this->property->path)
: [];
}
| public getValidationRules( ): iterable |
public function getValidationRules(): iterable
{
if ($this->validationRules === null) {
$rules = RulesNormalizer::normalize(null, $this->model);
$this->validationRules = $rules[$this->property->name] ?? [];
}
return $this->validationRules;
}
public function getValue(): mixed
{
return $this->model->getPropertyValue($this->property->name . $this->property->suffix);
}
| public isValidated( ): boolean |
public function isValidated(): bool
{
return $this->model->isValidated();
}
Signup or Login in order to comment.