eZ\Bundle\EzPublishCoreBundle\Features\Context\FieldTypeContext::addValueConstraint PHP Method

addValueConstraint() public method

Adds a validator to the stored field.
public addValueConstraint ( string $fieldType, string $value, string $constraint )
$fieldType string Type of the field
$value string Value of the constraint
$constraint string Constraint name
    public function addValueConstraint($fieldType, $value, $constraint)
    {
        $validatorName = $this->getFieldValidator($fieldType);
        $validatorParent = $validatorName . 'Validator';
        if ($this->fieldConstructionObject['fieldType']->validatorConfiguration == null) {
            $this->fieldConstructionObject['fieldType']->validatorConfiguration = array($validatorParent => array());
        }
        $value = is_numeric($value) ? $value + 0 : $value;
        $this->fieldConstructionObject['fieldType']->validatorConfiguration[$validatorParent][$constraint . $validatorName] = $value;
    }