/** * @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 array $arguments * @param callable $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return string */ 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 callable $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $table = $arguments['table']; $field = $arguments['field']; if ($table === NULL) { $currentRequest = $renderingContext->getControllerContext()->getRequest(); $moduleName = $currentRequest->getPluginName(); $table = '_MOD_' . $moduleName; } return '<div class="docheader-csh">' . BackendUtility::cshItem($table, $field) . '</div>'; }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return mixed */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $templateVariableContainer = $renderingContext->getTemplateVariableContainer(); $partialArguments = $arguments['arguments']; if (false === is_array($partialArguments)) { $partialArguments = []; } if (false === isset($partialArguments['settings']) && true === $templateVariableContainer->exists('settings')) { $partialArguments['settings'] = $templateVariableContainer->get('settings'); } $substKey = 'INT_SCRIPT.' . $GLOBALS['TSFE']->uniqueHash(); $content = '<!--' . $substKey . '-->'; $templateView = GeneralUtility::makeInstance('FluidTYPO3\\Vhs\\View\\UncacheTemplateView'); $GLOBALS['TSFE']->config['INTincScript'][$substKey] = ['type' => 'POSTUSERFUNC', 'cObj' => serialize($templateView), 'postUserFunc' => 'render', 'conf' => ['partial' => $arguments['partial'], 'section' => $arguments['section'], 'arguments' => $partialArguments, 'controllerContext' => $renderingContext->getControllerContext()], 'content' => $content]; return $content; }
/** * @param array $arguments * @param callable $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 RenderingContextInterface $renderingContext * @param array $arguments * @param \Closure $renderChildrenClosure * @return PipeInterface */ protected static function preparePipeInstance(RenderingContextInterface $renderingContext, array $arguments, \Closure $renderChildrenClosure = NULL) { $extensionName = $arguments['extensionName']; $controller = $arguments['controller']; $controllerContext = $renderingContext->getControllerContext(); if (TRUE === empty($extensionName)) { $extensionName = $controllerContext->getRequest()->getControllerExtensionName(); } if (TRUE === empty($controller)) { $controller = $controllerContext->getRequest()->getControllerObjectName(); } /** @var ControllerPipe $pipe */ $pipe = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('FluidTYPO3\\Flux\\Outlet\\Pipe\\ControllerPipe'); $pipe->setAction($arguments['action']); $pipe->setController($controller); $pipe->setExtensionName($extensionName); return $pipe; }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return mixed */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $extensionKey = $arguments['extensionKey']; $path = $arguments['path']; if (null === $extensionKey) { $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName(); $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); } if (!array_key_exists($extensionKey, $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'])) { return null; } elseif (!array_key_exists($extensionKey, static::$configurations)) { $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]); static::$configurations[$extensionKey] = GeneralUtility::removeDotsFromTS($extConf); } if (!$path) { return static::$configurations[$extensionKey]; } return ObjectAccess::getPropertyPath(static::$configurations[$extensionKey], $path); }
/** * @param array $arguments * @param callable $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(); if (!$historyEntry instanceof HistoryEntry) { return ''; } $historyLabel = LocalizationUtility::translate('changesInFields', $controllerContext->getRequest()->getControllerExtensionName(), array($historyEntry->getFieldlist())); $historyIcon = IconUtility::getSpriteIcon('actions-document-history-open', array('title' => LocalizationUtility::translate('showHistory', $controllerContext->getRequest()->getControllerExtensionName()))); $historyHref = BackendUtility::getModuleUrl('record_history', array('sh_uid' => $historyEntry->getUid(), 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'))); $historyLink = '<a href="' . htmlspecialchars($historyHref) . '">' . $historyIcon . '</a>'; return $historyLabel . ' ' . $historyLink; }
/** * @param array $arguments * @param callable $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 callable $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 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 static::$workspaceTitleRuntimeCache[$uid]; }
/** * 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 RenderingContextInterface $renderingContext * @param array $arguments * @return ControllerActions * @throws \RuntimeException */ public static function getComponent(RenderingContextInterface $renderingContext, array $arguments) { $extensionName = $arguments['controllerExtensionName']; $pluginName = $arguments['pluginName']; $actions = $arguments['actions']; $controllerName = $arguments['controllerName']; $separator = $arguments['separator']; $controllerContext = $renderingContext->getControllerContext(); if (TRUE === $actions instanceof \Traversable) { $actions = iterator_to_array($actions); } if (NULL !== $controllerContext) { if (TRUE === empty($extensionName)) { $request = $controllerContext->getRequest(); $extensionName = static::getFullExtensionNameFromRequest($request); } if (TRUE === empty($pluginName)) { $pluginName = $controllerContext->getRequest()->getPluginName(); } } if (TRUE === empty($extensionName) && TRUE === empty($pluginName) && 1 > count($actions)) { throw new \RuntimeException('Either "actions", or both "extensionName" and "pluginName" must be used on ' . 'flux:field.controllerActions. None were found and none were detected from the ControllerContext Request.', 1346514748); } /** @var ControllerActions $component */ $component = static::getPreparedComponent('ControllerActions', $renderingContext, $arguments); $component->setExtensionName(static::getExtensionNameFromRenderingContextOrArguments($renderingContext, $arguments)); $component->setItems($arguments['items']); $component->setControllerExtensionName($extensionName); $component->setPluginName($pluginName); $component->setControllerName($controllerName); $component->setActions($actions); $component->setExcludeActions($arguments['excludeActions']); $component->setPrefixOnRequiredArguments($arguments['prefixOnRequiredArguments']); $component->setDisableLocalLanguageLabels($arguments['disableLocalLanguageLabels']); $component->setLocalLanguageFileRelativePath($arguments['localLanguageFileRelativePath']); $component->setSubActions($arguments['subActions']); if (FALSE === empty($separator)) { $component->setSeparator($separator); } return $component; }
/** * 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; }
/** * @param RenderingContextInterface $renderingContext * @param array $arguments * @throws InvalidVariableException * @return string */ protected static function getExtensionNameFromRenderingContextOrArguments(RenderingContextInterface $renderingContext, array $arguments) { if (TRUE === isset($arguments[static::SCOPE_VARIABLE_EXTENSIONNAME])) { return $arguments[static::SCOPE_VARIABLE_EXTENSIONNAME]; } $viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); if (TRUE === $viewHelperVariableContainer->exists(static::SCOPE, static::SCOPE_VARIABLE_EXTENSIONNAME)) { return $viewHelperVariableContainer->get(static::SCOPE, static::SCOPE_VARIABLE_EXTENSIONNAME); } $controllerContext = $renderingContext->getControllerContext(); if (NULL !== $controllerContext) { $controllerExtensionName = $controllerContext->getRequest()->getControllerExtensionName(); $controllerVendorName = $controllerContext->getRequest()->getControllerVendorName(); return (FALSE === empty($controllerVendorName) ? $controllerVendorName . '.' : '') . $controllerExtensionName; } return 'FluidTYPO3.Flux'; }
/** * @test */ public function controllerContextCanBeReadCorrectly() { $controllerContext = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class, array(), array(), '', false); $this->renderingContext->setControllerContext($controllerContext); $this->assertSame($this->renderingContext->getControllerContext(), $controllerContext); }
/** * Injects a fresh rendering context * * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext * @return void */ public function setRenderingContext(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) { $this->baseRenderingContext = $renderingContext; $this->baseRenderingContext->getViewHelperVariableContainer()->setView($this); $this->controllerContext = $renderingContext->getControllerContext(); }
/** * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext * @return void */ public function setRenderingContext(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) { $this->renderingContext = $renderingContext; $this->templateVariableContainer = $renderingContext->getTemplateVariableContainer(); if ($renderingContext->getControllerContext() !== null) { $this->controllerContext = $renderingContext->getControllerContext(); } $this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); }
/** * @test */ public function controllerContextCanBeReadCorrectly() { $controllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array(), array(), '', FALSE); $this->renderingContext->setControllerContext($controllerContext); $this->assertSame($this->renderingContext->getControllerContext(), $controllerContext); }
/** * @param RenderingContextInterface $renderingContext * @throws InvalidVariableException * @return FormInterface */ public static function getFormFromRenderingContext(RenderingContextInterface $renderingContext) { $viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); $templateVariableContainer = $renderingContext->getTemplateVariableContainer(); if (TRUE === $viewHelperVariableContainer->exists(static::SCOPE, static::SCOPE_VARIABLE_FORM)) { $form = $viewHelperVariableContainer->get(static::SCOPE, static::SCOPE_VARIABLE_FORM); } elseif (TRUE === $templateVariableContainer->exists(static::SCOPE_VARIABLE_FORM)) { $form = $templateVariableContainer->get(static::SCOPE_VARIABLE_FORM); } else { $form = Form::create(array('extensionName' => $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName())); $viewHelperVariableContainer->add(static::SCOPE, static::SCOPE_VARIABLE_FORM, $form); } return $form; }