The methods getters of this class are accessible via the "context.userInformation" variable in security policies and thus are implicitly considered to be part of the public API. This UserService should be replaced by \Neos\Neos\Domain\Service\UserService in the long run.
 /**
  * Returns an array of usage reference objects.
  *
  * @param AssetInterface $asset
  * @return array<\Neos\Neos\Domain\Model\Dto\AssetUsageInNodeProperties>
  * @throws \Neos\ContentRepository\Exception\NodeConfigurationException
  */
 public function getUsageReferences(AssetInterface $asset)
 {
     $assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset);
     if (isset($this->firstlevelCache[$assetIdentifier])) {
         return $this->firstlevelCache[$assetIdentifier];
     }
     $userWorkspace = $this->userService->getPersonalWorkspace();
     $relatedNodes = [];
     foreach ($this->getRelatedNodes($asset) as $relatedNodeData) {
         $accessible = $this->domainUserService->currentUserCanReadWorkspace($relatedNodeData->getWorkspace());
         if ($accessible) {
             $context = $this->createContextMatchingNodeData($relatedNodeData);
         } else {
             $context = $this->createContentContext($userWorkspace->getName());
         }
         $site = $context->getCurrentSite();
         $node = $this->nodeFactory->createFromNodeData($relatedNodeData, $context);
         $flowQuery = new FlowQuery([$node]);
         /** @var \Neos\ContentRepository\Domain\Model\NodeInterface $documentNode */
         $documentNode = $flowQuery->closest('[instanceof Neos.Neos:Document]')->get(0);
         $relatedNodes[] = new AssetUsageInNodeProperties($asset, $site, $documentNode, $node, $accessible);
     }
     $this->firstlevelCache[$assetIdentifier] = $relatedNodes;
     return $this->firstlevelCache[$assetIdentifier];
 }
 /**
  * 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);
     }
     $username = $this->renderChildren();
     /* @var $requestedUser Person */
     $requestedUser = $this->domainUserService->getUser($username);
     if ($requestedUser === null || $requestedUser->getName() === null) {
         return $username;
     }
     $currentUser = $this->userService->getBackendUser();
     if ($currentUser) {
         if ($currentUser === $requestedUser) {
             $translationHelper = new TranslationHelper();
             $you = $translationHelper->translate('you', null, [], 'Main', 'Neos.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();
     }
 }
 /**
  * Get the current rendering mode (editPreviewMode).
  * Will return a live mode when not in backend.
  *
  * @return UserInterfaceMode
  */
 public function findModeByCurrentUser()
 {
     if ($this->userService->getBackendUser() === null || !$this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
         return $this->findModeByName('live');
     }
     /** @var \Neos\Neos\Domain\Model\User $user */
     $editPreviewMode = $this->userService->getUserPreference('contentEditing.editPreviewMode');
     if ($editPreviewMode === null) {
         $editPreviewMode = $this->defaultEditPreviewMode;
     }
     $mode = $this->findModeByName($editPreviewMode);
     return $mode;
 }
 /**
  * @test
  */
 public function getPersonalWorkspaceNameReturnsTheUsersWorkspaceNameIfAUserIsLoggedIn()
 {
     $mockUser = $this->getMockBuilder(User::class)->disableOriginalConstructor()->getMock();
     $this->mockUserDomainService->expects($this->atLeastOnce())->method('getCurrentUser')->will($this->returnValue($mockUser));
     $this->mockUserDomainService->expects($this->atLeastOnce())->method('getUserName')->with($mockUser)->will($this->returnValue('TheUserName'));
     $this->assertSame('user-TheUserName', $this->userService->getPersonalWorkspaceName());
 }
 /**
  * Returns the node this even refers to, if it can be resolved.
  *
  * It might happen that, if this event refers to a node contained in a site which is not available anymore,
  * Doctrine's proxy class of the Site domain model will fail with an EntityNotFoundException. We catch this
  * case and return NULL.
  *
  * @return NodeInterface
  */
 public function getNode()
 {
     try {
         $context = $this->contextFactory->create(array('workspaceName' => $this->userService->getUserWorkspace()->getName(), 'dimensions' => $this->dimension, 'currentSite' => $this->getCurrentSite(), 'invisibleContentShown' => true));
         return $context->getNodeByIdentifier($this->nodeIdentifier);
     } catch (EntityNotFoundException $e) {
         return null;
     }
 }
 /**
  * If the specified workspace or its root node does not exist yet, the workspace and root node will be created.
  *
  * This method is basically a safeguard for legacy and potentially broken websites where users might not have
  * their own workspace yet. In a normal setup, the Domain User Service is responsible for creating and deleting
  * user workspaces.
  *
  * @param string $workspaceName Name of the workspace
  * @return void
  */
 protected function createWorkspaceAndRootNodeIfNecessary($workspaceName)
 {
     $workspace = $this->workspaceRepository->findOneByName($workspaceName);
     if ($workspace === null) {
         $liveWorkspace = $this->workspaceRepository->findOneByName('live');
         $owner = $this->userService->getBackendUser();
         $workspace = new Workspace($workspaceName, $liveWorkspace, $owner);
         $this->workspaceRepository->add($workspace);
         $this->persistenceManager->whitelistObject($workspace);
     }
     $contentContext = $this->createContext($workspaceName);
     $rootNode = $contentContext->getRootNode();
     $this->persistenceManager->whitelistObject($rootNode);
     $this->persistenceManager->whitelistObject($rootNode->getNodeData());
     $this->persistenceManager->persistAll(true);
 }
 /**
  * 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 $languageIdentifier An identifier of a language to use (NULL for using the default language)
  * @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, $languageIdentifier = null)
 {
     if (preg_match(TranslationHelper::I18N_LABEL_ID_PATTERN, $id) === 1) {
         // In the longer run, this "extended ID" format should directly be resolved in the localization service
         list($package, $source, $id) = explode(':', $id, 3);
         $source = str_replace('.', '/', $source);
     }
     if ($languageIdentifier === null) {
         $languageIdentifier = $this->userService->getInterfaceLanguage();
     }
     // Catch exception in case the translation file doesn't exist, should be fixed in Flow 3.1
     try {
         $translation = parent::render($id, $value, $arguments, $source, $package, $quantity, $languageIdentifier);
         // Fallback to english label if label was not available in specific language
         if ($translation === $id && $languageIdentifier !== 'en') {
             $translation = parent::render($id, $value, $arguments, $source, $package, $quantity, 'en');
         }
         return $translation;
     } catch (Exception $exception) {
         return $value ?: $id;
     }
 }
 /**
  * @return string The current backend users interface language
  */
 public function render()
 {
     return $this->userService->getInterfaceLanguage();
 }
 /**
  * Get Related Nodes for an asset
  *
  * @param AssetInterface $asset
  * @return void
  */
 public function relatedNodesAction(AssetInterface $asset)
 {
     $userWorkspace = $this->userService->getPersonalWorkspace();
     $usageReferences = $this->assetService->getUsageReferences($asset);
     $relatedNodes = [];
     /** @var AssetUsageInNodeProperties $usage */
     foreach ($usageReferences as $usage) {
         $documentNodeIdentifier = $usage->getDocumentNode() instanceof NodeInterface ? $usage->getDocumentNode()->getIdentifier() : null;
         $relatedNodes[$usage->getSite()->getNodeName()]['site'] = $usage->getSite();
         $relatedNodes[$usage->getSite()->getNodeName()]['documentNodes'][$documentNodeIdentifier]['node'] = $usage->getDocumentNode();
         $relatedNodes[$usage->getSite()->getNodeName()]['documentNodes'][$documentNodeIdentifier]['nodes'][] = ['node' => $usage->getNode(), 'nodeData' => $usage->getNode()->getNodeData(), 'contextDocumentNode' => $usage->getDocumentNode(), 'accessible' => $usage->isAccessible()];
     }
     $this->view->assignMultiple(['asset' => $asset, 'relatedNodes' => $relatedNodes, 'contentDimensions' => $this->contentDimensionPresetSource->getAllPresets(), 'userWorkspace' => $userWorkspace]);
 }
 /**
  * Set the locale according to the user settings
  *
  * @return void
  */
 protected function initializeObject()
 {
     $this->_localizationService->getConfiguration()->setCurrentLocale(new Locale($this->_userService->getInterfaceLanguage()));
 }