0 follower

Abstract Class Yiisoft\FormModel\FormModel

InheritanceYiisoft\FormModel\FormModel
ImplementsYiisoft\FormModel\FormModelInterface

A base class for form models that represent HTML forms: their data, validation and presentation.

Constants

Hide inherited constants

Constant Value Description Defined By
META_HINT 2 Yiisoft\FormModel\FormModel
META_LABEL 1 Yiisoft\FormModel\FormModel
META_PLACEHOLDER 3 Yiisoft\FormModel\FormModel

Method Details

Hide inherited methods

addError() public method

public Yiisoft\FormModel\FormModel addError ( string $message, array $valuePath = [] )
$message string
$valuePath array

                public function addError(string $message, array $valuePath = []): static
{
    $this->getValidationResult()->addErrorWithoutPostProcessing($message, valuePath: $valuePath);
    return $this;
}

            
getFormName() public method

public string getFormName ( )

                public function getFormName(): string
{
    if (str_contains(static::class, '@anonymous')) {
        return '';
    }
    $className = strrchr(static::class, '\\');
    if ($className === false) {
        return static::class;
    }
    return substr($className, 1);
}

            
getPropertyHint() public method

public string getPropertyHint ( string $property )
$property string

                public function getPropertyHint(string $property): string
{
    return $this->readPropertyMetaValue(self::META_HINT, $property) ?? '';
}

            
getPropertyHints() public method

public array getPropertyHints ( )

                public function getPropertyHints(): array
{
    return [];
}

            
getPropertyLabel() public method

public string getPropertyLabel ( string $property )
$property string

                public function getPropertyLabel(string $property): string
{
    return $this->readPropertyMetaValue(self::META_LABEL, $property) ?? $this->generatePropertyLabel($property);
}

            
getPropertyLabels() public method

public array getPropertyLabels ( )

                public function getPropertyLabels(): array
{
    return [];
}

            
getPropertyPlaceholder() public method

public string getPropertyPlaceholder ( string $property )
$property string

                public function getPropertyPlaceholder(string $property): string
{
    return $this->readPropertyMetaValue(self::META_PLACEHOLDER, $property) ?? '';
}

            
getPropertyPlaceholders() public method

public array getPropertyPlaceholders ( )

                public function getPropertyPlaceholders(): array
{
    return [];
}

            
getPropertyValue() public method

public mixed getPropertyValue ( string $property )
$property string

                public function getPropertyValue(string $property): mixed
{
    try {
        return $this->readPropertyValue($property);
    } catch (PropertyNotSupportNestedValuesException $exception) {
        return $exception->getValue() === null
            ? null
            : throw $exception;
    } catch (UndefinedArrayElementException) {
        return null;
    }
}

            
getValidationResult() public method

public \Yiisoft\Validator\Result getValidationResult ( )

                public function getValidationResult(): Result
{
    if (empty($this->validationResult)) {
        throw new LogicException('Validation result is not set.');
    }
    return $this->validationResult;
}

            
hasProperty() public method

public boolean hasProperty ( string $property )
$property string

                public function hasProperty(string $property): bool
{
    try {
        $this->readPropertyValue($property);
    } catch (ValueNotFoundException) {
        return false;
    }
    return true;
}

            
isValid() public method

public boolean isValid ( )

                public function isValid(): bool
{
    return $this->isValidated() && $this->getValidationResult()->isValid();
}

            
isValidated() public method

public boolean isValidated ( )

                public function isValidated(): bool
{
    return $this->validationResult !== null;
}

            
processValidationResult() public method

public void processValidationResult ( \Yiisoft\Validator\Result $result )
$result \Yiisoft\Validator\Result

                public function processValidationResult(Result $result): void
{
    $this->validationResult = $result;
}