Final Class Yiisoft\FormModel\FormModelInputData
| Inheritance | Yiisoft\FormModel\FormModelInputData |
|---|---|
| Implements | Yiisoft\Form\Field\Base\InputData\InputDataInterface |
Public Methods
Method Details
| public mixed __construct ( Yiisoft\FormModel\FormModelInterface $model, string $property ) | ||
| $model | Yiisoft\FormModel\FormModelInterface | |
| $property | string | |
public function __construct(
private readonly FormModelInterface $model,
string $property,
) {
$this->property = new ParsedProperty($property);
}
| public string|null getHint ( ) |
public function getHint(): ?string
{
return $this->model->getPropertyHint($this->getPropertyName());
}
Generates an appropriate input ID.
This method converts the result {@see \Yiisoft\FormModel\getName()} into a valid input ID.
For example, if {@see \Yiisoft\FormModel\getInputName()} returns Post[content], this method will return post-content.
| public string getId ( ) | ||
| 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 string|null getLabel ( ) |
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 {@see \Yiisoft\FormModel\getPropertyName()} for explanation of property expression.
| public string getName ( ) | ||
| 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 string|null getPlaceholder ( ) |
public function getPlaceholder(): ?string
{
$placeholder = $this->model->getPropertyPlaceholder($this->getPropertyName());
return $placeholder === '' ? null : $placeholder;
}
| public array getValidationErrors ( ) |
public function getValidationErrors(): array
{
/** @psalm-var list<string> */
return $this->model->isValidated()
? $this->model->getValidationResult()->getPropertyErrorMessagesByPath($this->property->path)
: [];
}
| public iterable getValidationRules ( ) |
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 boolean isValidated ( ) |
public function isValidated(): bool
{
return $this->model->isValidated();
}
Signup or Login in order to comment.