/** * @return mixed|string * @throws InvalidStateException */ public function getContent() { if (!is_null($this->component->getFixedContent())) { return $this->component->getFixedContent(); } elseif (!is_null($this->component->getContentCallback())) { return call_user_func($this->component->getContentCallback(), $this->state, $this); } elseif (!is_null($this->component->getTranslationKey())) { return $this->state->getServices()->getTranslator()->translateRaw($this->component->getTranslationKey(), $this->component, $this->state, $this->component->getTranslationParams()); } return ''; }
/** * @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); }
/** * @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); }
/** * @param ComponentInterface $subject * @param FormState $state * @param $condition * @param array $params * @return bool */ protected function conditionIsValid(ComponentInterface $subject, FormState $state, $condition, array $params) { // get the condition instance from the pool $condition = $state->getServices()->getConditions()->get($condition); // check the condition return $condition->isValid($subject, $state, $params); }