Beispiel #1
0
 /**
  * @param ComponentInterface $source
  * @param FormState $state
  * @param $inputName
  * @param string $validator
  * @param ...$params
  * @return bool
  */
 public function validate(ComponentInterface $source, FormState $state, $inputName, $validator = Validator::HAS_VALUE, ...$params)
 {
     // if the input has no value (NULL), always return false
     if ($state->hasValue($inputName, $source->getParent()) === false) {
         return false;
     }
     // try to get the validator from the services
     $validator = $state->getServices()->getValidators()->get($validator);
     // get the current value for the target component
     $sourceValue = $state->getValue($inputName, $source->getParent());
     // return if the validator validates
     return $validator->validate($sourceValue, $params);
 }