/** * @test */ public function controllerContextCanBeReadCorrectly() { $controllerContext = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class, array('getRequest'), array(), '', false); $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($this->getMock(Request::class)); $this->renderingContext->setControllerContext($controllerContext); $this->assertSame($this->renderingContext->getControllerContext(), $controllerContext); }
/** * @param RenderingContextInterface $renderingContext * @return void */ public function setRenderingContext(RenderingContextInterface $renderingContext) { $this->renderingContext = $renderingContext; $this->templateVariableContainer = $renderingContext->getVariableProvider(); $this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); if ($renderingContext instanceof FlowAwareRenderingContextInterface) { $this->controllerContext = $renderingContext->getControllerContext(); } }
/** * Render the URI to the resource. The filename is used from child content. * * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return string The URI to the resource */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $path = $arguments['path']; $extensionName = $arguments['extensionName']; $absolute = $arguments['absolute']; if ($extensionName === null) { $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName(); } $uri = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path; $uri = GeneralUtility::getFileAbsFileName($uri); $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri); if (TYPO3_MODE === 'BE' && $absolute === false && $uri !== false) { $uri = '../' . $uri; } if ($absolute === true) { $uri = $renderingContext->getControllerContext()->getRequest()->getBaseUri() . $uri; } return $uri; }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $table = $arguments['table']; $field = $arguments['field']; $wrap = $arguments['wrap']; if ($table === null) { $currentRequest = $renderingContext->getControllerContext()->getRequest(); $moduleName = $currentRequest->getPluginName(); $table = '_MOD_' . $moduleName; } return '<div class="docheader-csh">' . BackendUtility::cshItem($table, $field, '', $wrap) . '</div>'; }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $pageUid = $arguments['pageUid']; $additionalParams = $arguments['additionalParams']; $pageType = $arguments['pageType']; $noCache = $arguments['noCache']; $noCacheHash = $arguments['noCacheHash']; $section = $arguments['section']; $linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages']; $absolute = $arguments['absolute']; $addQueryString = $arguments['addQueryString']; $argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString']; $addQueryStringMethod = $arguments['addQueryStringMethod']; $uriBuilder = $renderingContext->getControllerContext()->getUriBuilder(); $uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setAddQueryStringMethod($addQueryStringMethod)->build(); return $uri; }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $getVars = $arguments['getVars']; $setVars = $arguments['setVars']; $mayMakeShortcut = $GLOBALS['BE_USER']->mayMakeShortcut(); if ($mayMakeShortcut) { $doc = GeneralUtility::makeInstance(DocumentTemplate::class); $currentRequest = $renderingContext->getControllerContext()->getRequest(); $extensionName = $currentRequest->getControllerExtensionName(); $moduleName = $currentRequest->getPluginName(); if (count($getVars) === 0) { $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName); $getVars = array('id', 'M', $modulePrefix); } $getList = implode(',', $getVars); $setList = implode(',', $setVars); return $doc->makeShortcutIcon($getList, $setList, $moduleName); } return ''; }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $uid = $arguments['uid']; if (isset(static::$workspaceTitleRuntimeCache[$uid])) { return htmlspecialchars(static::$workspaceTitleRuntimeCache[$uid]); } if ($uid === 0) { static::$workspaceTitleRuntimeCache[$uid] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('live', $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName()); } elseif (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')) { static::$workspaceTitleRuntimeCache[$uid] = ''; } else { $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); $workspaceRepository = $objectManager->get(\TYPO3\CMS\Belog\Domain\Repository\WorkspaceRepository::class); /** @var $workspace \TYPO3\CMS\Belog\Domain\Model\Workspace */ $workspace = $workspaceRepository->findByUid($uid); // $workspace may be null, force empty string in this case static::$workspaceTitleRuntimeCache[$uid] = $workspace === null ? '' : $workspace->getTitle(); } return htmlspecialchars(static::$workspaceTitleRuntimeCache[$uid]); }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ $objectManager = GeneralUtility::makeInstance(ObjectManager::class); /** @var \TYPO3\CMS\Belog\Domain\Repository\HistoryEntryRepository $historyEntryRepository */ $historyEntryRepository = $objectManager->get(HistoryEntryRepository::class); /** @var \TYPO3\CMS\Belog\Domain\Model\HistoryEntry $historyEntry */ $historyEntry = $historyEntryRepository->findOneBySysLogUid($arguments['uid']); /** @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext */ $controllerContext = $renderingContext->getControllerContext(); /** @var IconFactory $iconFactory */ $iconFactory = GeneralUtility::makeInstance(IconFactory::class); if (!$historyEntry instanceof HistoryEntry) { return ''; } $historyLabel = LocalizationUtility::translate('changesInFields', $controllerContext->getRequest()->getControllerExtensionName(), array($historyEntry->getFieldlist())); $titleLable = LocalizationUtility::translate('showHistory', $controllerContext->getRequest()->getControllerExtensionName()); $historyIcon = $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render(); $historyHref = BackendUtility::getModuleUrl('record_history', array('sh_uid' => $historyEntry->getUid(), 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'))); $historyLink = '<a href="' . htmlspecialchars($historyHref) . '" title="' . htmlspecialchars($titleLable) . '">' . $historyIcon . '</a>'; return $historyLabel . ' ' . $historyLink; }
/** * Resolve workspace title from UID. * * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * * @return string workspace title or UID * @throws \InvalidArgumentException */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { if (!$renderingContext instanceof RenderingContext) { throw new \InvalidArgumentException('The given rendering context is not of type "TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext"', 1468363946); } $uid = $arguments['uid']; if (isset(static::$workspaceTitleRuntimeCache[$uid])) { return static::$workspaceTitleRuntimeCache[$uid]; } if ($uid === 0) { static::$workspaceTitleRuntimeCache[$uid] = LocalizationUtility::translate('live', $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName()); } elseif (!ExtensionManagementUtility::isLoaded('workspaces')) { static::$workspaceTitleRuntimeCache[$uid] = ''; } else { $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $workspaceRepository = $objectManager->get(WorkspaceRepository::class); /** @var \TYPO3\CMS\Belog\Domain\Model\Workspace $workspace */ $workspace = $workspaceRepository->findByUid($uid); // $workspace may be null, force empty string in this case static::$workspaceTitleRuntimeCache[$uid] = $workspace === null ? '' : $workspace->getTitle(); } return static::$workspaceTitleRuntimeCache[$uid]; }
/** * Return array element by key. * * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @throws InvalidVariableException * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $key = $arguments['key']; $id = $arguments['id']; $default = $arguments['default']; $htmlEscape = $arguments['htmlEscape']; $extensionName = $arguments['extensionName']; $arguments = $arguments['arguments']; // Wrapper including a compatibility layer for TYPO3 Flow Translation if ($id === null) { $id = $key; } if ((string) $id === '') { throw new InvalidVariableException('An argument "key" or "id" has to be provided', 1351584844); } $request = $renderingContext->getControllerContext()->getRequest(); $extensionName = $extensionName === null ? $request->getControllerExtensionName() : $extensionName; $value = static::translate($id, $extensionName, $arguments); if ($value === null) { $value = $default !== null ? $default : $renderChildrenClosure(); if (!empty($arguments)) { $value = vsprintf($value, $arguments); } } elseif ($htmlEscape) { $value = htmlspecialchars($value); } return $value; }
/** * Render the "Base" tag by outputting $request->getBaseUri() * * Note: renders as <base></base>, because IE6 will else refuse to display * the page... * * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * * @return string "base"-Tag. * @api */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $controllerContext = $renderingContext->getControllerContext(); return '<base href="' . htmlspecialchars($controllerContext->getRequest()->getBaseUri()) . '" />'; }
/** * @param \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext * @return void */ public function setRenderingContext(\TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) { $this->renderingContext = $renderingContext; $this->templateVariableContainer = $renderingContext->getVariableProvider(); $this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); if ($renderingContext instanceof \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext) { $this->controllerContext = $renderingContext->getControllerContext(); } }
/** * @param null $arguments * @param RenderingContextInterface $renderingContext * @return boolean */ protected static function evaluateCondition($arguments = null, RenderingContextInterface $renderingContext) { $objectManager = $renderingContext->getObjectManager(); /** @var PolicyService $policyService */ $policyService = $objectManager->get(PolicyService::class); /** @var Context $securityContext */ $securityContext = $objectManager->get(Context::class); $role = $arguments['role']; $account = $arguments['account']; $packageKey = isset($arguments['packageKey']) ? $arguments['packageKey'] : $renderingContext->getControllerContext()->getRequest()->getControllerPackageKey(); if (is_string($role)) { $roleIdentifier = $role; if (in_array($roleIdentifier, ['Everybody', 'Anonymous', 'AuthenticatedUser'])) { $roleIdentifier = 'Neos.Flow:' . $roleIdentifier; } if (strpos($roleIdentifier, '.') === false && strpos($roleIdentifier, ':') === false) { $roleIdentifier = $packageKey . ':' . $roleIdentifier; } $role = $policyService->getRole($roleIdentifier); } $hasRole = $securityContext->hasRole($role->getIdentifier()); if ($account instanceof Account) { $hasRole = $account->hasRole($role); } return $hasRole; }