/**
  * Check if a form has a localized version and deliver it if available
  *
  * @param $formName
  * @param $localeOverride
  * @return string
  */
 public function getFormNameRespectingLocale($formName, $localeOverride = '')
 {
     // if we override the locale anyway (and it isn't english), we return early
     if (!empty($localeOverride) && $localeOverride !== 'en') {
         return $formName . ucfirst($localeOverride);
     }
     $currentLanguage = $this->i18nService->getConfiguration()->getCurrentLocale()->getLanguage();
     /*
      * a localized version has the language iso code as uppercased suffix, e.g. dataSheetFormFr
      * english is the default language and has no suffix, therefore we return the unchanged name if
      * no translation was found
      */
     if ($this->formPersistenceManager->exists($formName . ucfirst($currentLanguage))) {
         $formName = $formName . ucfirst($currentLanguage);
     }
     return $formName;
 }
Пример #2
0
 /**
  * This takes a form identifier and returns a unique persistence identifier for it.
  * By default this is just similar to the identifier. But if a form with the same persistence identifier already
  * exists a suffix is appended until the persistence identifier is unique.
  *
  * @param string $formIdentifier lowerCamelCased form identifier
  * @return string unique form persistence identifier
  */
 protected function findUniquePersistenceIdentifier($formIdentifier)
 {
     if (!$this->formPersistenceManager->exists($formIdentifier)) {
         return $formIdentifier;
     }
     for ($attempts = 1; $attempts < 100; $attempts++) {
         $formPersistenceIdentifier = sprintf('%s_%d', $formIdentifier, $attempts);
         if (!$this->formPersistenceManager->exists($formPersistenceIdentifier)) {
             return $formPersistenceIdentifier;
         }
     }
     throw new \TYPO3\Flow\Exception(sprintf('Could not find a unique persistence identifier for form identifier "%s" after %d attempts', $formIdentifier, $attempts), 1329842768);
 }