* @author Cedric Ziel * @author Stefan Neufeind * @package Vhs * @subpackage ViewHelpers */ class ExtensionConfigurationViewHelper extends AbstractViewHelper { /** * @param array $source TypoScript-array with dots: $source['foo.']['bar.']['baz'] * @param string $path * @return mixed */ protected function extractFromArrayByPath($source, $path) { $result = $source; $pathParts = explode('.', $path); $pathParts = array_diff($pathParts, array('')); foreach ($pathParts as $part) { if (array_key_exists($part . '.', $result)) { $result = $result[$part . '.']; } elseif (array_key_exists($part, $result)) { $result = $result[$part]; } else { return NULL; } } return $result; } /** * @param string $path * @param string $extensionKey * @param string $name (deprecated, just use $path instead) * @return string * @throws Exception */ public function render($path = NULL, $extensionKey = NULL, $name = NULL) { if (NULL !== $path) { $pathToExtract = $path; } elseif (NULL !== $name) { $pathToExtract = $name; GeneralUtility::deprecationLog('v:variable.extensionConfiguration was called with parameter "name" which is deprecated. Use "path" instead.'); } else { throw new Exception('v:variable.extensionConfiguration requires the "path" attribute to be filled.', 1446998437); } if (NULL === $extensionKey) { $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName(); $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); } if (FALSE === array_key_exists($extensionKey, $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'])) { return NULL; } $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]); return $this->extractFromArrayByPath($extConf, $path); } }