Example #1
0
 /**
  * @param ComponentInterface $source
  * @param FormState $state
  * @param array $params
  * @return bool
  * @throws FormException
  */
 public function isValid(ComponentInterface $source, FormState $state, array $params = array())
 {
     if (!isset($params[0])) {
         throw new FormException(sprintf("Missing callable for condition of type 'callback' for component '%s'!", $source->getId()), 'condition.missingCallback');
     } elseif (!is_callable($params[0])) {
         throw new FormException(sprintf("Invalid callable for condition of type 'callback' for component '%s'!", $source->getId()), 'condition.incorrectCallback');
     }
     if (isset($params[1]) && (bool) $params[1]) {
         return call_user_func($params[0], $source, $state);
     } else {
         return call_user_func($params[0], $source);
     }
 }
Example #2
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);
 }
Example #3
0
 /**
  * @param ComponentInterface $source
  * @param FormState $state
  * @param string $validator
  * @param ...$params
  * @return bool
  */
 public function evaluate(ComponentInterface $source, FormState $state, $validator = Validator::HAS_VALUE, ...$params)
 {
     //print_rf($source->getValue());
     // if it is not a data unit component, always return false
     if (!$source instanceof DataUnitComponentInterface) {
         return false;
     }
     // try to get the validator from the services
     $validator = $state->getServices()->getValidators()->get($validator);
     //print_rf($source->describe());
     //exit;
     // return if the validator validates
     return $validator->validate($source->getValue(), $params);
 }
Example #4
0
 /**
  * @param ComponentInterface $component
  */
 public function registerComponent(ComponentInterface $component)
 {
     $this->componentsById[$component->getFullId()] = $component;
     // register value if it is a data unit
     if ($component instanceof DataUnitComponentInterface) {
         if (!$component->shouldIgnoreValue()) {
             $this->values[$component->getFullName()] = $component->getValue();
         }
         $this->componentsByName[$component->getFullName()] = $component;
     }
 }
Example #5
0
 /**
  * @param ComponentInterface $component
  * @return string
  */
 protected function replaceParentFullName(ComponentInterface $component)
 {
     $parent = $component->getParent();
     if (is_null($parent)) {
         return '';
     } elseif ($parent instanceof DataUnitComponentInterface) {
         return $this->processPath($parent->getFullName());
     }
     return '';
 }