0 follower

Final Class Yiisoft\FormModel\FormModelInputData

InheritanceYiisoft\FormModel\FormModelInputData
ImplementsYiisoft\Form\Field\Base\InputData\InputDataInterface

Method Details

Hide inherited methods

__construct() public method

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);
}

            
getHint() public method

public getHint( ): string|null

                public function getHint(): ?string
{
    return $this->model->getPropertyHint($this->getPropertyName());
}

            
getId() public method

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);
}

            
getLabel() public method

public getLabel( ): string|null

                public function getLabel(): ?string
{
    return $this->model->getPropertyLabel($this->getPropertyName() . $this->property->suffix);
}

            
getName() public method

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.');
}

            
getPlaceholder() public method

public getPlaceholder( ): string|null

                public function getPlaceholder(): ?string
{
    $placeholder = $this->model->getPropertyPlaceholder($this->getPropertyName());
    return $placeholder === '' ? null : $placeholder;
}

            
getValidationErrors() public method

public getValidationErrors( ): array

                public function getValidationErrors(): array
{
    /** @psalm-var list<string> */
    return $this->model->isValidated()
        ? $this->model->getValidationResult()->getPropertyErrorMessagesByPath($this->property->path)
        : [];
}

            
getValidationRules() public method

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;
}

            
getValue() public method

public getValue( ): mixed
throws Yiisoft\FormModel\Exception\UndefinedObjectPropertyException
throws Yiisoft\FormModel\Exception\StaticObjectPropertyException
throws Yiisoft\FormModel\Exception\PropertyNotSupportNestedValuesException
throws Yiisoft\FormModel\Exception\ValueNotFoundException

                public function getValue(): mixed
{
    return $this->model->getPropertyValue($this->property->name . $this->property->suffix);
}

            
isValidated() public method

public isValidated( ): boolean

                public function isValidated(): bool
{
    return $this->model->isValidated();
}