TYPO3 CMS  TYPO3_8-7
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 
26 
32 {
34 
40  protected static $workspaceTitleRuntimeCache = [];
41 
45  public function initializeArguments()
46  {
47  parent::initializeArguments();
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 }
static translate($key, $extensionName=null, $arguments=null)
static makeInstance($className,... $constructorArguments)