Beispiel #1
0
 /**
  * @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), '.');
 }
Beispiel #2
0
 /**
  * @param ComponentInterface $component
  * @param FormState $state
  * @return string
  */
 public function replaceBla(ComponentInterface $component, FormState $state)
 {
     return $state->getFormId();
 }
Beispiel #3
0
 /**
  * @param FormState $context
  * @return string
  */
 public function getTestContent(FormState $context)
 {
     return $context->getFormId();
 }