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