‪TYPO3CMS  9.5
WorkspaceTitleViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
26 
31 class ‪WorkspaceTitleViewHelper extends AbstractViewHelper
32 {
33  use CompileWithRenderStatic;
34 
40  protected static ‪$workspaceTitleRuntimeCache = [];
41 
45  public function ‪initializeArguments()
46  {
47  $this->registerArgument('uid', 'int', 'UID of the workspace', true);
48  }
49 
60  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
61  {
62  if (!$renderingContext instanceof ‪RenderingContext) {
63  throw new \InvalidArgumentException('The given rendering context is not of type "TYPO3\CMS\Fluid\Core\Rendering\RenderingContext"', 1468363946);
64  }
65 
66  $uid = $arguments['uid'];
67  if (isset(static::$workspaceTitleRuntimeCache[$uid])) {
68  return static::$workspaceTitleRuntimeCache[$uid];
69  }
70 
71  if ($uid === 0) {
72  static::$workspaceTitleRuntimeCache[$uid] = ‪LocalizationUtility::translate(
73  'live',
74  $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName()
75  );
76  } elseif (!‪ExtensionManagementUtility::isLoaded('workspaces')) {
77  static::$workspaceTitleRuntimeCache[$uid] = '';
78  } else {
79  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
80  $workspaceRepository = $objectManager->get(WorkspaceRepository::class);
82  $workspace = $workspaceRepository->findByUid($uid);
83  // $workspace may be null, force empty string in this case
84  static::$workspaceTitleRuntimeCache[$uid] = $workspace === null ? '' : $workspace->getTitle();
85  }
86 
87  return static::$workspaceTitleRuntimeCache[$uid];
88  }
89 }
‪TYPO3\CMS\Belog\ViewHelpers
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:29
‪TYPO3\CMS\Belog\ViewHelpers\WorkspaceTitleViewHelper\$workspaceTitleRuntimeCache
‪static array $workspaceTitleRuntimeCache
Definition: WorkspaceTitleViewHelper.php:38
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:36
‪TYPO3\CMS\Belog\ViewHelpers\WorkspaceTitleViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: WorkspaceTitleViewHelper.php:58
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate($key, $extensionName=null, $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:63
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key, $exitOnError=null)
Definition: ExtensionManagementUtility.php:115
‪TYPO3\CMS\Belog\ViewHelpers\WorkspaceTitleViewHelper\initializeArguments
‪initializeArguments()
Definition: WorkspaceTitleViewHelper.php:43
‪TYPO3\CMS\Belog\ViewHelpers\WorkspaceTitleViewHelper
Definition: WorkspaceTitleViewHelper.php:32
‪TYPO3\CMS\Belog\Domain\Repository\WorkspaceRepository
Definition: WorkspaceRepository.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:36
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25