/**
  * Executes this finisher
  * @see AbstractFinisher::execute()
  *
  * @return void
  * @throws FinisherException
  */
 protected function executeInternal()
 {
     $formRuntime = $this->finisherContext->getFormRuntime();
     $labelId = $this->parseOption('translation.id');
     if ($labelId !== NULL) {
         $locale = NULL;
         $localeIdentifier = $this->parseOption('translation.locale');
         if ($localeIdentifier !== NULL) {
             try {
                 $locale = new Locale($localeIdentifier);
             } catch (InvalidLocaleIdentifierException $exception) {
                 throw new FinisherException(sprintf('"%s" is not a valid locale identifier.', $locale), 1421325113, $exception);
             }
         }
         $messagePackageKey = $this->parseOption('translation.package');
         if ($messagePackageKey === NULL) {
             $renderingOptions = $formRuntime->getRenderingOptions();
             $messagePackageKey = $renderingOptions['translationPackage'];
         }
         $message = $this->translator->translateById($labelId, array(), NULL, $locale, $this->parseOption('translation.source'), $messagePackageKey);
     } else {
         $message = $this->parseOption('message');
     }
     $formRuntime->getResponse()->setContent($message);
 }
 /**
  * @param \Lelesys\Plugin\News\Domain\Model\Folder $folder
  * @return void
  */
 public function deleteAction(\Lelesys\Plugin\News\Domain\Model\Folder $folder)
 {
     $this->folderService->delete($folder);
     $packageKey = $this->settings['flashMessage']['packageKey'];
     $header = 'Deleted the folder.';
     $message = $this->translator->translateById('lelesys.plugin.news.delete.folder', array(), NULL, NULL, 'Main', $packageKey);
     $this->addFlashMessage($message, $header, \TYPO3\Flow\Error\Message::SEVERITY_OK);
     $this->redirect('index');
 }
 /**
  * Adds the given new comment object to the comment repository
  *
  * @Flow\Validate(type="\Lelesys\Captcha\Validators\CaptchaValidator", value="$captcha")
  * @Flow\Validate(type="NotEmpty", value="$captcha")
  * @param \Lelesys\Plugin\News\Domain\Model\Comment $newComment A new comment to add
  * @param \Lelesys\Plugin\News\Domain\Model\News $news
  * @param string $captcha Captcha for comment
  * @return void
  */
 public function createAction(\Lelesys\Plugin\News\Domain\Model\Comment $newComment, \Lelesys\Plugin\News\Domain\Model\News $news, $captcha = NULL)
 {
     try {
         $this->commentService->create($newComment, $news);
         $array = array("news" => $news);
         $this->addFlashMessage($this->translator->translateById('lelesys.plugin.news.comment.created', array(), NULL, NULL, 'Main', $this->settings['flashMessage']['packageKey']));
         $this->redirect("show", "News", "Lelesys.Plugin.News", $array);
     } catch (Lelesys\Plugin\News\Domain\Service\Exception $exception) {
         $packageKey = $this->settings['flashMessage']['packageKey'];
         $header = 'Sorry, error occured. Please try again later.';
         $message = $this->translator->translateById('lelesys.plugin.news.try.again', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, \TYPO3\Flow\Error\Message::SEVERITY_ERROR);
     }
 }
 /**
  * Retrieves a user from crowd and prints their attributes
  * @param string $userName
  */
 public function showUserCommand($userName)
 {
     $validAttributes = $this->settings['additionalAttributes']['user'];
     $headerRow = ['Name', 'Fullname'];
     foreach ($validAttributes as $attribute) {
         $headerRow[] = $this->translator->translateById('attribute.' . $attribute, [], null, null, 'CrowdApi', 'Neos.NeosIo');
     }
     $user = $this->crowdApiConnector->fetchUser($userName, false);
     $attributes = [$user['name'], $user['display-name']];
     foreach ($validAttributes as $attribute) {
         $attributes[] = array_key_exists($attribute, $user) ? $user[$attribute] : '';
     }
     $this->output->outputTable([$attributes], $headerRow);
 }
 /**
  * Removes the given file object from the file repository
  *
  * @param \Lelesys\Plugin\News\Domain\Model\File $file The file to delete
  * @return void
  */
 public function deleteAction(\Lelesys\Plugin\News\Domain\Model\File $file)
 {
     $packageKey = $this->settings['flashMessage']['packageKey'];
     try {
         $this->fileService->delete($file);
         $header = 'Deleted a file.';
         $message = $this->translator->translateById('lelesys.plugin.news.delete.file', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, \TYPO3\Flow\Error\Message::SEVERITY_OK);
         $this->redirect('index');
     } catch (Lelesys\Plugin\News\Domain\Service\Exception $exception) {
         $header = 'Sorry, error occured. Please try again later.';
         $message = $this->translator->translateById('lelesys.plugin.news.try.again', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, '', \TYPO3\Flow\Error\Message::SEVERITY_ERROR);
     }
 }
 /**
  * @test
  * @dataProvider translationFallbackDataProvider
  * @param string $id
  * @param string $value
  * @param string $translatedId
  * @param string $translatedValue
  * @param string $expectedResult
  */
 public function translationFallbackTests($id, $value, $translatedId, $translatedValue, $expectedResult)
 {
     $this->mockTranslator->expects($this->any())->method('translateById', $id)->will($this->returnValue($translatedId));
     $this->mockTranslator->expects($this->any())->method('translateByOriginalLabel', $value)->will($this->returnValue($translatedValue));
     $actualResult = $this->translateViewHelper->render($id, $value);
     $this->assertSame($expectedResult, $actualResult);
 }
 /**
  * @test
  */
 public function viewHelperReturnsIdWhenRenderChildrenReturnsEmptyResultIfIdIsNotFound()
 {
     $this->mockTranslator->expects($this->once())->method('translateById', 'some.label', 'Main', 'TYPO3.Flow', array(), NULL, $this->dummyLocale)->will($this->returnValue('some.label'));
     $this->translateViewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(NULL));
     $result = $this->translateViewHelper->render('some.label', NULL, array(), 'Main', NULL, NULL, 'de_DE');
     $this->assertEquals('some.label', $result);
 }
 /**
  * Renders the translated label.
  *
  * Replaces all placeholders with corresponding values if they exist in the
  * translated label.
  *
  * @param string $id Id to use for finding translation (trans-unit id in XLIFF)
  * @param string $value If $key is not specified or could not be resolved, this value is used. If this argument is not set, child nodes will be used to render the default
  * @param array $arguments Numerically indexed array of values to be inserted into placeholders
  * @param string $source Name of file with translations
  * @param string $package Target package key. If not set, the current package key will be used
  * @param mixed $quantity A number to find plural form for (float or int), NULL to not use plural forms
  * @param string $locale An identifier of locale to use (NULL for use the default locale)
  * @return string Translated label or source label / ID key
  * @throws ViewHelper\Exception
  */
 public function render($id = NULL, $value = NULL, array $arguments = array(), $source = 'Main', $package = NULL, $quantity = NULL, $locale = NULL)
 {
     $localeObject = NULL;
     if ($locale !== NULL) {
         try {
             $localeObject = new Locale($locale);
         } catch (InvalidLocaleIdentifierException $e) {
             throw new ViewHelper\Exception('"' . $locale . '" is not a valid locale identifier.', 1279815885);
         }
     }
     if ($package === NULL) {
         $package = $this->controllerContext->getRequest()->getControllerPackageKey();
     }
     $originalLabel = $value === NULL ? $this->renderChildren() : $value;
     if ($id === NULL) {
         return $this->translator->translateByOriginalLabel($originalLabel, $arguments, $quantity, $localeObject, $source, $package);
     } else {
         $translation = $this->translator->translateById($id, $arguments, $quantity, $localeObject, $source, $package);
         if ($translation === $id) {
             if ($originalLabel) {
                 return $this->translator->translateByOriginalLabel($originalLabel, $arguments, $quantity, $localeObject, $source, $package);
             } else {
                 return $id;
             }
         } else {
             return $translation;
         }
     }
 }
 /**
  * Discards content of the whole workspace
  *
  * @param Workspace $workspace
  * @return void
  */
 public function discardWorkspaceAction(Workspace $workspace)
 {
     $unpublishedNodes = $this->publishingService->getUnpublishedNodes($workspace);
     $this->publishingService->discardNodes($unpublishedNodes);
     $this->addFlashMessage($this->translator->translateById('workspaces.allChangesInWorkspaceHaveBeenDiscarded', [htmlspecialchars($workspace->getTitle())], null, null, 'Modules', 'TYPO3.Neos'));
     $this->redirect('index');
 }
 /**
  * @param string $emailAddress
  * @param string $requirement
  *
  * @throws \Exception
  *
  * @return string
  */
 public function resetPasswordAction($emailAddress, $requirement = '')
 {
     if ($requirement !== '') {
         throw new \Exception('Bot detection', 12393182738);
     }
     $locale = new Locale('nl');
     $account = $this->accountRepository->findActiveByAccountIdentifierAndAuthenticationProviderName($emailAddress, 'DefaultProvider');
     if ($account instanceof Account) {
         try {
             /** @var Person $profile */
             $profile = $this->profileService->getProfileNodeOfAccount($account);
             $password = $this->randomPassword();
             $hashedPassword = $this->hashService->hashPassword($password, 'default');
             $this->mailerService->sendEmail(array('email' => $emailAddress, 'name' => $profile->getDisplayName()), 'Nieuw wachtwoord', 'Packages/Application/BuJitsuDo.Authentication/Resources/Private/Templates/Email/PasswordReset.html', array('password' => $password, 'profile' => $profile));
             $account->setCredentialsSource($hashedPassword);
             $this->accountRepository->update($account);
             $this->persistenceManager->persistAll();
         } catch (\Exception $exception) {
             return $exception->getMessage();
         }
     } else {
         $this->response->setHeader('Notification', $this->translator->translateById('profile.reset.password.response.failure', [], NULL, $locale, 'Main', 'BuJitsuDo.Authentication'));
         $this->response->setHeader('NotificationType', 'alert');
         return '';
     }
     $this->response->setHeader('Notification', $this->translator->translateById('profile.reset.password.response.success', [], NULL, $locale, 'Main', 'BuJitsuDo.Authentication'));
     $this->response->setHeader('NotificationType', 'success');
     return '';
 }
Beispiel #11
0
 /**
  * Is called if authentication failed.
  *
  * @param AuthenticationRequiredException $exception The exception thrown while the authentication process
  * @return void
  */
 protected function onAuthenticationFailure(AuthenticationRequiredException $exception = null)
 {
     $responseIdentifier = 0;
     /** @var TokenInterface $token */
     foreach ($this->authenticationManager->getTokens() as $token) {
         if ($token->getAuthenticationStatus() > $responseIdentifier) {
             $responseIdentifier = $token->getAuthenticationStatus();
         }
     }
     $locale = $this->localizationService->getConfiguration()->getCurrentLocale();
     $package = $this->controllerContext->getRequest()->getControllerPackageKey();
     $this->view->assign('value', array('responseText' => $this->translator->translateById('authentication.response.' . $responseIdentifier, array(), NULL, $locale, 'Main', $package), 'responseIdentifier' => $responseIdentifier));
     if ($this->request->getHttpRequest()->getMethod() !== 'OPTIONS') {
         $this->response->setStatus(401);
     }
 }
 /**
  * Check if $value is valid. If it is not valid, needs to add an errorw
  * to Result.
  *
  * @param AssetInterface $value
  * @return void
  */
 protected function isValid($value)
 {
     $fileName = $value->getTitle() ?: $value->getResource()->getFilename();
     /** @var Query $query */
     $query = $this->entityManager->createQuery('SELECT a FROM TYPO3\\Media\\Domain\\Model\\Asset a JOIN a.resource r WHERE (a.title = :fileName OR r.filename = :fileName) AND a.Persistence_Object_Identifier != :assetIdentifier');
     $query->setParameter('fileName', $fileName);
     $query->setParameter('assetIdentifier', $this->persistenceManager->getIdentifierByObject($value));
     $result = $query->getArrayResult();
     // We need to exclude ImageVariant objects, but can not do that in the DQL query
     $result = array_filter($result, function ($value) {
         return $value['dtype'] !== 'typo3_media_imagevariant';
     });
     if (count($result) > 0) {
         $this->addError($this->translator->translateById('assetWithTitleAlreadyExists', [$fileName], null, $this->_localizationService->getConfiguration()->getCurrentLocale(), 'Main', 'Flownative.Neos.UniqueFilenames'), 1462705529);
     }
 }
 /**
  * Checks a given Domain Name to be syntactically correct regarding the naming rules
  * in the relevant RFCs.
  *
  * @param string $domainName the domain name to validate
  * @return bool the result of the validation, TRUE if all is fine, FALSE otherwise
  */
 protected function isValid($domainName)
 {
     $this->domainNameToCheck = $this->idnaConvertService->encodeUmlautDomainName($domainName);
     if ($this->checkForValidNumberOfLabels() && $this->checkForValidLengthOfSingleLabels() && $this->checkLength() && $this->checkForAtLeastOneDot() && $this->checkForAllowedCharacters() && $this->checkForNumberOnlyLabels() && $this->checkForDashesAtBeginEndOfLabels()) {
         // all seems to be fine
         return TRUE;
     } else {
         // TODO: Find a nicer solution. Currently the translator cannot be injected properly during unit-tests
         if ($this->isSilentModeActive === TRUE) {
             $this->addError('invalid domain name', 1409169479);
         } else {
             $this->addError($this->translator->translateById('message.error_invalid_domain_name', array(), NULL, NULL, 'Domain', 'Roketi.Panel'), 1403357765);
         }
         return FALSE;
     }
 }
 /**
  * Renders the translated label.
  * Replaces all placeholders with corresponding values if they exist in the
  * translated label.
  *
  * @param string $id Id to use for finding translation (trans-unit id in XLIFF)
  * @param string $value If $key is not specified or could not be resolved, this value is used. If this argument is not set, child nodes will be used to render the default
  * @param array $arguments Numerically indexed array of values to be inserted into placeholders
  * @param string $source Name of file with translations
  * @param string $package Target package key. If not set, the current package key will be used
  * @param mixed $quantity A number to find plural form for (float or int), NULL to not use plural forms
  * @param string $locale An identifier of locale to use (NULL for use the default locale)
  * @return string Translated label or source label / ID key
  * @throws ViewHelperException
  */
 public function render($id = null, $value = null, array $arguments = array(), $source = 'Main', $package = null, $quantity = null, $locale = null)
 {
     $localeObject = null;
     if ($locale !== null) {
         try {
             $localeObject = new Locale($locale);
         } catch (InvalidLocaleIdentifierException $e) {
             throw new ViewHelperException(sprintf('"%s" is not a valid locale identifier.', $locale), 1279815885);
         }
     }
     if ($package === null) {
         $package = $this->controllerContext->getRequest()->getControllerPackageKey();
         if ($package === null) {
             throw new ViewHelperException('The current package key can\'t be resolved. Make sure to initialize the Fluid view with a proper ActionRequest and/or specify the "package" argument when using the f:translate ViewHelper', 1416832309);
         }
     }
     $originalLabel = $value === null ? $this->renderChildren() : $value;
     if ($id === null) {
         return $this->translator->translateByOriginalLabel($originalLabel, $arguments, $quantity, $localeObject, $source, $package);
     } else {
         $translation = $this->translator->translateById($id, $arguments, $quantity, $localeObject, $source, $package);
         if ($translation === $id) {
             if ($originalLabel) {
                 return $this->translator->translateByOriginalLabel($originalLabel, $arguments, $quantity, $localeObject, $source, $package);
             } else {
                 return $id;
             }
         } else {
             return $translation;
         }
     }
 }
 /**
  * @param string $identifier
  * @return string
  */
 protected function translate($identifier)
 {
     $translation = $this->translator->translateById($identifier, [], null, null, $this->getTranslationSource(), $this->getPackageKey());
     if ($translation === $identifier) {
         return null;
     }
     return $translation;
 }
 /**
  * @test
  */
 public function fallsBackToIdIfNoTranslationCouldBeFoundForIdAndValueIsNotSet()
 {
     $translateParameterToken = new TranslationParameterToken();
     $this->inject($translateParameterToken, 'translator', $this->mockTranslator);
     $this->mockTranslator->expects($this->once())->method('translateById', 'SomeId', array('a', 'couple', 'of', 'arguments'), 42, 'de_DE', 'SomeSource', 'Some.PackageKey')->willReturn('SomeId');
     $result = $translateParameterToken->id('SomeId')->arguments(array('a', 'couple', 'of', 'arguments'))->quantity(42)->locale('de_DE')->source('SomeSource')->package('Some.PackageKey')->translate();
     $this->assertEquals('SomeId', $result);
 }
Beispiel #17
0
 /**
  * @return \Incvisio\LostFound\Domain\Model\User
  */
 public function getCurrentUser()
 {
     if ($this->securityContext->getAccount() != NULL) {
         return $this->securityContext->getAccount()->getParty();
     } else {
         $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error($this->translator->translateById('main.messages.pleaseLogin', array(), NULL, NULL, 'Main', 'Incvisio.LostFound')));
         $this->redirect('index', 'Standard');
     }
 }
 /**
  * Add a translated flashMessage.
  *
  * @param string $messageBody The translation id for the message body.
  * @param string $messageTitle The translation id for the message title.
  * @param string $severity
  * @param array $messageArguments
  * @param integer $messageCode
  * @return void
  */
 public function addFlashMessage($messageBody, $messageTitle = '', $severity = Message::SEVERITY_OK, array $messageArguments = array(), $messageCode = null)
 {
     if (is_string($messageBody)) {
         $translatedMessageBody = $this->translator->translateById($messageBody, $messageArguments, null, null, 'Main', 'TYPO3.Media');
         if ($translatedMessageBody !== null) {
             $messageBody = $translatedMessageBody;
         }
     }
     $messageTitle = $this->translator->translateById($messageTitle, $messageArguments, null, null, 'Main', 'TYPO3.Media');
     parent::addFlashMessage($messageBody, $messageTitle, $severity, $messageArguments, $messageCode);
 }
 /**
  * @param string $property
  * @param FormElementInterface $element
  * @return string the rendered form head
  */
 public function render($property, FormElementInterface $element = null)
 {
     if ($element === null) {
         $element = $this->renderChildren();
     }
     if ($property === 'label') {
         $defaultValue = $element->getLabel();
     } else {
         $defaultValue = isset($element->getProperties()[$property]) ? (string) $element->getProperties()[$property] : '';
     }
     $renderingOptions = $element->getRenderingOptions();
     if (!isset($renderingOptions['translationPackage'])) {
         return $defaultValue;
     }
     $translationId = sprintf('forms.elements.%s.%s', $element->getIdentifier(), $property);
     try {
         $translation = $this->translator->translateById($translationId, [], null, null, 'Main', $renderingOptions['translationPackage']);
     } catch (ResourceException $exception) {
         return $defaultValue;
     }
     return $translation === null ? $defaultValue : $translation;
 }
 /**
  * @test
  */
 public function translateByIdReturnsTranslationIfOneNumericArgumentIsGiven()
 {
     $mockTranslationProvider = $this->getAccessibleMock(\TYPO3\Flow\I18n\TranslationProvider\XliffTranslationProvider::class);
     $mockTranslationProvider->expects($this->once())->method('getTranslationById')->with('id', $this->defaultLocale, NULL, 'source', 'packageKey')->will($this->returnValue('Translated label'));
     $mockFormatResolver = $this->getMock(\TYPO3\Flow\I18n\FormatResolver::class);
     $mockFormatResolver->expects($this->once())->method('resolvePlaceholders')->with('Translated label', array(1.0), $this->defaultLocale)->will($this->returnValue('Formatted and translated label'));
     $mockPluralsReader = $this->getMock(\TYPO3\Flow\I18n\Cldr\Reader\PluralsReader::class);
     $mockPluralsReader->expects($this->never())->method('getPluralForm');
     $this->translator->injectTranslationProvider($mockTranslationProvider);
     $this->translator->injectFormatResolver($mockFormatResolver);
     $this->translator->injectPluralsReader($mockPluralsReader);
     $result = $this->translator->translateById('id', array(1.0), NULL, NULL, 'source', 'packageKey');
     $this->assertEquals('Formatted and translated label', $result);
 }
 /**
  * Removes the given tag objTagControllerect from the tag repository
  *
  * @param \Lelesys\Plugin\News\Domain\Model\Tag $tag The tag to delete
  * @return void
  */
 public function deleteAction(\Lelesys\Plugin\News\Domain\Model\Tag $tag)
 {
     try {
         $this->tagService->delete($tag);
         $header = 'Deleted a tag.';
         $message = $this->translator->translateById('lelesys.plugin.news.delete.tag', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, \TYPO3\Flow\Error\Message::SEVERITY_OK);
         $this->redirect('index');
     } catch (Lelesys\Plugin\News\Domain\Service\Exception $exception) {
         $header = 'Sorry, error occured. Please try again later.';
         $message = $this->translator->translateById('lelesys.plugin.news.try.again', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, \TYPO3\Flow\Error\Message::SEVERITY_ERROR);
     }
 }
 /**
  * Render user initials or an abbreviated name for a given username. If the account was deleted, use the username as fallback.
  *
  * @param string $format Supported are "fullFirstName" and "initials"
  * @return string
  */
 public function render($format = 'initials')
 {
     if (!in_array($format, array('fullFirstName', 'initials', 'fullName'))) {
         throw new \InvalidArgumentException(sprintf('Format "%s" given to history:userInitials(), only supporting "fullFirstName", "initials" and "fullName".', $format), 1415705861);
     }
     $accountIdentifier = $this->renderChildren();
     // TODO: search by credential source is still needed
     /* @var $account \TYPO3\Flow\Security\Account */
     $account = $this->accountRepository->findOneByAccountIdentifier($accountIdentifier);
     if ($account === null) {
         return $accountIdentifier;
     }
     /* @var $requestedUser Person */
     $requestedUser = $account->getParty();
     if ($requestedUser === null || $requestedUser->getName() === null) {
         return $accountIdentifier;
     }
     if ($this->securityContext->canBeInitialized()) {
         if ($this->securityContext->getAccount()) {
             /** @var User $currentUser */
             $currentUser = $this->securityContext->getAccount()->getParty();
             if ($currentUser === $requestedUser) {
                 $languageIdentifier = $currentUser->getPreferences()->get('interfaceLanguage') ? $currentUser->getPreferences()->get('interfaceLanguage') : $this->defaultLanguageIdentifier;
                 $you = $translation = $this->translator->translateById('you', array(), 1, new Locale($languageIdentifier), 'Main', 'TYPO3.Neos');
             }
         }
     }
     switch ($format) {
         case 'initials':
             return mb_substr($requestedUser->getName()->getFirstName(), 0, 1) . mb_substr($requestedUser->getName()->getLastName(), 0, 1);
         case 'fullFirstName':
             return isset($you) ? $you : $requestedUser->getName()->getFirstName() . ' ' . mb_substr($requestedUser->getName()->getLastName(), 0, 1) . '.';
         case 'fullName':
             return isset($you) ? $you : $requestedUser->getName()->getFullName();
     }
 }
 /**
  * show's the hidden category
  *
  * @param \Lelesys\Plugin\News\Domain\Model\Category $category
  * @return void
  */
 public function showCategoryAction(\Lelesys\Plugin\News\Domain\Model\Category $category)
 {
     $packageKey = $this->settings['flashMessage']['packageKey'];
     try {
         $this->categoryService->showCategory($category);
         $header = 'Category is Visible';
         $message = $this->translator->translateById('lelesys.plugin.category.visible', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, \TYPO3\Flow\Error\Message::SEVERITY_OK);
         $this->redirect('index');
     } catch (Lelesys\Plugin\News\Domain\Service\Exception $exception) {
         $header = 'Sorry, error occured. Please try again later.';
         $message = $this->translator->translateById('lelesys.plugin.news.try.again', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, '', \TYPO3\Flow\Error\Message::SEVERITY_ERROR);
     }
 }
 /**
  * show's the hidden category
  *
  * @param \Lelesys\Plugin\News\Domain\Model\Comment $comment
  * @return void
  */
 public function publishAction(\Lelesys\Plugin\News\Domain\Model\Comment $comment)
 {
     try {
         $this->commentService->publishComment($comment);
         $packageKey = $this->settings['flashMessage']['packageKey'];
         $header = 'Comment is published.';
         $message = $this->translator->translateById('lelesys.plugin.news.publish.comment', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, \TYPO3\Flow\Error\Message::SEVERITY_OK);
         $this->redirect('index');
     } catch (Lelesys\NeoNews\Domain\Service\Exception $exception) {
         $packageKey = $this->settings['flashMessage']['packageKey'];
         $header = 'Sorry, error occured. Please try again later.';
         $message = $this->translator->translateById('lelesys.plugin.news.try.again', array(), NULL, NULL, 'Main', $packageKey);
         $this->addFlashMessage($message, $header, \TYPO3\Flow\Error\Message::SEVERITY_ERROR);
     }
 }
 /**
  * Translate according to currently collected parameters
  *
  * @param array $overrides An associative array to override the collected parameters
  * @return string
  */
 public function translate(array $overrides = [])
 {
     array_replace_recursive($this->parameters, $overrides);
     $id = isset($this->parameters['id']) ? $this->parameters['id'] : null;
     $value = isset($this->parameters['value']) ? $this->parameters['value'] : null;
     $arguments = isset($this->parameters['arguments']) ? $this->parameters['arguments'] : [];
     $source = isset($this->parameters['source']) ? $this->parameters['source'] : 'Main';
     $package = isset($this->parameters['package']) ? $this->parameters['package'] : null;
     $quantity = isset($this->parameters['quantity']) ? $this->parameters['quantity'] : null;
     $locale = isset($this->parameters['locale']) ? $this->parameters['locale'] : null;
     if ($id === null) {
         return $this->translator->translateByOriginalLabel($value, $arguments, $quantity, $locale, $source, $package);
     }
     $translation = $this->translator->translateById($id, $arguments, $quantity, $locale, $source, $package);
     if ($translation === null && $value !== null) {
         return $this->translator->translateByOriginalLabel($value, $arguments, $quantity, $locale, $source, $package);
     }
     return $translation;
 }
 /**
  * If ui.help.message is set in $configuration, translate it if requested and then convert it from markdown to HTML.
  *
  * @param array $configuration
  * @param string $idPrefix
  * @param string $nodeTypeName
  * @return void
  */
 protected function translateAndConvertHelpMessage(array &$configuration, $idPrefix, $nodeTypeName = null)
 {
     $helpMessage = '';
     if (isset($configuration['ui']['help'])) {
         // message handling
         if (isset($configuration['ui']['help']['message'])) {
             if ($this->shouldFetchTranslation($configuration['ui']['help'], 'message')) {
                 $translationIdentifier = $this->splitIdentifier($idPrefix . 'ui.help.message');
                 $helpMessage = $this->translator->translateById($translationIdentifier['id'], [], null, null, $translationIdentifier['source'], $translationIdentifier['packageKey']);
             } else {
                 $helpMessage = $configuration['ui']['help']['message'];
             }
         }
         // prepare thumbnail
         if ($nodeTypeName !== null) {
             $thumbnailUrl = '';
             if (isset($configuration['ui']['help']['thumbnail'])) {
                 $thumbnailUrl = $configuration['ui']['help']['thumbnail'];
                 if (strpos($thumbnailUrl, 'resource://') === 0) {
                     $thumbnailUrl = $this->resourceManager->getPublicPackageResourceUriByPath($thumbnailUrl);
                 }
             } else {
                 # look in well know location
                 $splitPrefix = $this->splitIdentifier($nodeTypeName);
                 $relativePathAndFilename = 'NodeTypes/Thumbnails/' . $splitPrefix['id'] . '.png';
                 $resourcePath = 'resource://' . $splitPrefix['packageKey'] . '/Public/' . $relativePathAndFilename;
                 if (file_exists($resourcePath)) {
                     $thumbnailUrl = $this->resourceManager->getPublicPackageResourceUriByPath($resourcePath);
                 }
             }
             if ($thumbnailUrl !== '') {
                 $helpMessage = '![alt text](' . $thumbnailUrl . ') ' . $helpMessage;
             }
         }
         if ($helpMessage !== '') {
             $helpMessage = $this->markdownConverter->convertToHtml($helpMessage);
             $helpMessage = $this->addTargetAttribute($helpMessage);
         }
     }
     $configuration['ui']['help']['message'] = $helpMessage;
 }
 /**
  * Returns a translated version of the given label
  *
  * @param string $value option tag value
  * @param string $label option tag label
  * @return string
  * @throws ViewHelper\Exception
  * @throws Fluid\Exception
  */
 protected function getTranslatedLabel($value, $label)
 {
     $translationConfiguration = $this->arguments['translate'];
     $translateBy = isset($translationConfiguration['by']) ? $translationConfiguration['by'] : 'id';
     $sourceName = isset($translationConfiguration['source']) ? $translationConfiguration['source'] : 'Main';
     $packageKey = isset($translationConfiguration['package']) ? $translationConfiguration['package'] : $this->controllerContext->getRequest()->getControllerPackageKey();
     $prefix = isset($translationConfiguration['prefix']) ? $translationConfiguration['prefix'] : '';
     if (isset($translationConfiguration['locale'])) {
         try {
             $localeObject = new Locale($translationConfiguration['locale']);
         } catch (InvalidLocaleIdentifierException $e) {
             throw new ViewHelper\Exception('"' . $translationConfiguration['locale'] . '" is not a valid locale identifier.', 1330013193);
         }
     } else {
         $localeObject = NULL;
     }
     switch ($translateBy) {
         case 'label':
             $label = isset($translationConfiguration['using']) && $translationConfiguration['using'] === 'value' ? $value : $label;
             return $this->translator->translateByOriginalLabel($label, array(), NULL, $localeObject, $sourceName, $packageKey);
         case 'id':
             $id = $prefix . (isset($translationConfiguration['using']) && $translationConfiguration['using'] === 'label' ? $label : $value);
             return $this->translator->translateById($id, array(), NULL, $localeObject, $sourceName, $packageKey);
         default:
             throw new Fluid\Exception('You can only request to translate by "label" or by "id", but asked for "' . $translateBy . '" in your SelectViewHelper tag.', 1340050647);
     }
 }
 /**
  * @test
  * @dataProvider labelAndLocaleForTranslation
  */
 public function simpleTranslationByLabelWorks($label, $locale, $translation)
 {
     $result = $this->translator->translateByOriginalLabel($label, array(), NULL, $locale, 'Main', 'TYPO3.Flow');
     $this->assertEquals($translation, $result);
 }
 /**
  * @test
  */
 public function translationByIdReturnsNullOnFailure()
 {
     $result = $this->translator->translateById('non-existing-id');
     $this->assertNull($result);
 }
 /**
  * Get translation for specified id from Main.xlf from current package.
  *
  * @param string $labelId
  * @param array $arguments
  * @return mixed
  */
 protected function translateById($labelId, array $arguments = array())
 {
     return $this->translator->translateById($labelId, $arguments, null, null, 'Main', $this->request->getControllerPackageKey());
 }