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

            
getHint() public method

public string|null getHint ( )

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

            
getId() public method

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

            
getLabel() public method

public string|null getLabel ( )

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

            
getPlaceholder() public method

public string|null getPlaceholder ( )

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

            
getValidationErrors() public method

public array getValidationErrors ( )

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

            
getValidationRules() public method

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

            
getValue() public method

public mixed getValue ( )
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 boolean isValidated ( )

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