/** * @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 $key * @param ComponentInterface $component * @param FormState $state * @return string * @throws FormException */ public function parse($key, ComponentInterface $component, FormState $state) { $customCallbacks = $this->customCallbacks; $callback = function (array $matches) use($component, $state, $key, $customCallbacks) { if (!isset($matches[2])) { return ''; } $wildcard = $matches[2]; switch ($wildcard) { case self::TYPE: return $this->replaceType($component); case self::BASETYPE: return $this->replaceBaseType($component); case self::ID: return $component->getId(); case self::ID_FULL: return $component->getFullId(); case self::PARENT_ID: return $this->replaceParentId($component); case self::PARENT_ID_FULL: return $this->replaceParentFullId($component); case self::NAME: return $this->replaceName($component); case self::NAME_FULL: return $this->replaceFullName($component); case self::PARENT_NAME: return $this->replaceParentName($component); case self::PARENT_NAME_FULL: return $this->replaceParentFullName($component); case self::FORM_ID: return $state->getFormId(); default: // try to load a custom wildcard replacement callback if (isset($customCallbacks[$wildcard])) { /** @var TranslationKeyWildcardInterface $wc */ $wc = $customCallbacks[$wildcard]; return $wc->replace($component, $state); } // if no custom callback, fail throw new FormException(sprintf("Unknown translation key wildcard '%s'", $wildcard), 'translation.keyWildcardUnknown', array('wildcard' => $wildcard, 'key' => $key)); } }; $key = preg_replace_callback('/({([a-zA-Z0-9]+)})/', $callback, $key); if (is_null($key)) { throw new FormException(sprintf("Cannot parse translation key '%s': invalid format!", $key), 'translation.keyParseError', array('key' => $key)); } return trim(str_replace('..', '.', $key), '.'); }
/** * @param ComponentInterface $component * @param FormState $state * @return string */ public function replaceBla(ComponentInterface $component, FormState $state) { return $state->getFormId(); }
/** * @param FormState $context * @return string */ public function getTestContent(FormState $context) { return $context->getFormId(); }
/** * @param ComponentInterface $source * @param FormState $state * @param $target * @param $property * @throws \Exception */ public function validate(ComponentInterface $source, FormState $state, $target, $property) { $target = $state->getComponentByName($target); //echo $target->getFullId(); }
/** * @param FormState $state * @return null|string */ protected function readInput(FormState $state) { return $state->hasInput($this->getName()); }
/** * @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); }
/** * @param FormState $state * @return bool */ protected function shouldReadInput(FormState $state) { return $state->hasSubmit() && !$this->hasFixedValue(); }
/** * @param DataUnitComponentInterface $input * @param FormState $state * @return null|string */ protected function readInput(DataUnitComponentInterface $input, FormState $state) { // only load input value if it actually was set if ($state->hasInput($input->getFullName())) { return $this->preprocessInputValue($input, $state->getInput($input->getFullName())); } return null; }