‪TYPO3CMS  11.5
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 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25 
30 class ‪WorkspaceTitleViewHelper extends AbstractViewHelper
31 {
32  use CompileWithRenderStatic;
33 
39  protected static ‪$workspaceTitleRuntimeCache = [];
40 
44  public function ‪initializeArguments()
45  {
46  $this->registerArgument('uid', 'int', 'UID of the workspace', true);
47  }
48 
59  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
60  {
61  if (!$renderingContext instanceof ‪RenderingContext) {
62  throw new \InvalidArgumentException('The given rendering context is not of type "TYPO3\CMS\Fluid\Core\Rendering\RenderingContext"', 1468363946);
63  }
64 
65  $uid = $arguments['uid'];
66  if (isset(static::$workspaceTitleRuntimeCache[$uid])) {
67  return static::$workspaceTitleRuntimeCache[$uid];
68  }
69 
70  if ($uid === 0) {
71  static::$workspaceTitleRuntimeCache[$uid] = ‪LocalizationUtility::translate(
72  'live',
73  $renderingContext->getRequest()->getControllerExtensionName()
74  );
75  } elseif (!‪ExtensionManagementUtility::isLoaded('workspaces')) {
76  static::$workspaceTitleRuntimeCache[$uid] = '';
77  } else {
78  $workspace = BackendUtility::getRecord('sys_workspace', $uid);
79  static::$workspaceTitleRuntimeCache[$uid] = $workspace['title'] ?? '';
80  }
81 
82  return static::$workspaceTitleRuntimeCache[$uid];
83  }
84 }
‪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:37
‪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:57
‪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:42
‪TYPO3\CMS\Belog\ViewHelpers\WorkspaceTitleViewHelper
Definition: WorkspaceTitleViewHelper.php:31
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:37
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114