/** * @test */ public function convertPlainArrayToTypoScriptArrayAddsNodeValueAndTrailingDots() { $extbaseTS = array('10' => array('value' => 'Hallo', '_typoScriptNodeValue' => 'TEXT')); $classic = array('10' => 'TEXT', '10.' => array('value' => 'Hallo')); $converted = Tx_Extbase_Utility_TypoScript::convertPlainArrayToTypoScriptArray($extbaseTS); $this->assertEquals($converted, $classic); }
/** * Download a file * * @param string $file Path to the file * @param array $configuration configuration used to render the filelink cObject * @param boolean $hideError define if an error should be displayed if file not found * * @param string $class optional class * * @param string $target target * * @param string $alt alt text * * @param string $title title text * @return string * @throws Tx_Fluid_Core_ViewHelper_Exception_InvalidVariableException */ public function render($file, $configuration = array(), $hideError = FALSE, $class = '', $target = '', $alt = '', $title = '') { if (!is_file($file)) { $errorMessage = sprintf('Given file "%s" for %s is not valid', htmlspecialchars($file), get_class()); t3lib_div::devLog($errorMessage, 'news', t3lib_div::SYSLOG_SEVERITY_WARNING); if (!$hideError) { throw new Tx_Fluid_Core_ViewHelper_Exception_InvalidVariableException('Given file is not a valid file: ' . htmlspecialchars($file)); } } $cObj = t3lib_div::makeInstance('tslib_cObj'); $fileInformation = pathinfo($file); $fileInformation['file'] = $file; $fileInformation['size'] = filesize($file); $cObj->data = $fileInformation; // set a basic configuration for cObj->filelink $tsConfiguration = array('path' => $fileInformation['dirname'] . '/', 'ATagParams' => 'class="download-link basic-class ' . strtolower($fileInformation['extension']) . '"', 'labelStdWrap.' => array('cObject.' => array('value' => $this->renderChildren()))); // Fallback if no configuration given if (!is_array($configuration)) { $configuration = array('labelStdWrap.' => array('cObject' => 'TEXT')); } else { if (class_exists('Tx_Extbase_Utility_TypoScript')) { $configuration = Tx_Extbase_Utility_TypoScript::convertPlainArrayToTypoScriptArray($configuration); } else { /** @var $typoscriptService Tx_Extbase_Service_TypoScriptService */ $typoscriptService = t3lib_div::makeInstance('Tx_Extbase_Service_TypoScriptService'); $configuration = $typoscriptService->convertPlainArrayToTypoScriptArray($configuration); } } // merge default configuration with optional configuration $tsConfiguration = t3lib_div::array_merge_recursive_overrule($tsConfiguration, $configuration); if (!empty($class)) { $tsConfiguration['ATagParams'] .= ' class="' . $class . '"'; } if (!empty($target)) { $tsConfiguration['target'] = $target; } if (!empty($alt)) { $tsConfiguration['altText'] = $alt; } if (!empty($title)) { $tsConfiguration['titleText'] = $title; } // generate link $link = $cObj->filelink($fileInformation['basename'], $tsConfiguration); return $link; }
/** * Loads the Extbase Framework configuration. * * The Extbase framework configuration HAS TO be retrieved using this method, as they are come from different places than the normal settings. * Framework configuration is, in contrast to normal settings, needed for the Extbase framework to operate correctly. * * @param string $extensionName if specified, the configuration for the given extension will be returned (plugin.tx_extensionname) * @param string $pluginName if specified, the configuration for the given plugin will be returned (plugin.tx_extensionname_pluginname) * @return array the Extbase framework configuration */ public function getConfiguration($extensionName = NULL, $pluginName = NULL) { // 1st level cache if ($extensionName !== NULL) { if ($pluginName === NULL) { throw new Tx_Extbase_Configuration_Exception('You\'ll have to specify either both, extensionName and pluginName, or neither.', 1289852422); } $configurationCacheKey = strtolower($extensionName . '_' . $pluginName); } else { $configurationCacheKey = strtolower($this->extensionName . '_' . $this->pluginName); } if (isset($this->configurationCache[$configurationCacheKey])) { return $this->configurationCache[$configurationCacheKey]; } $frameworkConfiguration = $this->getExtbaseConfiguration(); if (!isset($frameworkConfiguration['persistence']['storagePid'])) { $frameworkConfiguration['persistence']['storagePid'] = self::DEFAULT_BACKEND_STORAGE_PID; } // only merge $this->configuration and override switchableControllerActions when retrieving configuration of the current plugin if ($extensionName === NULL || $extensionName === $this->extensionName && $pluginName === $this->pluginName) { $pluginConfiguration = $this->getPluginConfiguration($this->extensionName, $this->pluginName); $pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, $this->configuration); $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($this->extensionName, $this->pluginName); if (isset($this->configuration['switchableControllerActions'])) { $this->overrideSwitchableControllerActions($pluginConfiguration, $this->configuration['switchableControllerActions']); } } else { $pluginConfiguration = $this->getPluginConfiguration($extensionName, $pluginName); $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($extensionName, $pluginName); } $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, $pluginConfiguration); // only load context specific configuration when retrieving configuration of the current plugin if ($extensionName === NULL || $extensionName === $this->extensionName && $pluginName === $this->pluginName) { $frameworkConfiguration = $this->getContextSpecificFrameworkConfiguration($frameworkConfiguration); } if (!empty($frameworkConfiguration['persistence']['storagePid']) && is_array($frameworkConfiguration['persistence']['storagePid'])) { /** * We simulate the frontend to enable the use of cObjects in * stdWrap. Than we convert the configuration to normal TypoScript * and apply the stdWrap to the storagePid */ Tx_Extbase_Utility_FrontendSimulator::simulateFrontendEnvironment($this->getContentObject()); $conf = Tx_Extbase_Utility_TypoScript::convertPlainArrayToTypoScriptArray($frameworkConfiguration['persistence']); $frameworkConfiguration['persistence']['storagePid'] = $GLOBALS['TSFE']->cObj->stdWrap($conf['storagePid'], $conf['storagePid.']); Tx_Extbase_Utility_FrontendSimulator::resetFrontendEnvironment(); } // 1st level cache $this->configurationCache[$configurationCacheKey] = $frameworkConfiguration; return $frameworkConfiguration; }
/** * Returns an array with Typoscript the old way (with dot). * * Extbase converts the "classical" TypoScript (with trailing dot) to a format without trailing dot, * to be more future-proof and not to have any conflicts with Fluid object accessor syntax. * However, if you want to call legacy TypoScript objects, you somehow need the "old" syntax (because this is what TYPO3 is used to). * With this method, you can convert the extbase TypoScript to classical TYPO3 TypoScript which is understood by the rest of TYPO3. * * @param array $plainArray An Typoscript Array with Extbase Syntax (without dot but with _typoScriptNodeValue) * @return array array with Typoscript as usual (with dot) * @api */ public static function convertPlainArrayToTypoScriptArray($plainArray) { $typoScriptArray = array(); if (is_array($plainArray)) { foreach ($plainArray as $key => $value) { if (is_array($value)) { if (isset($value['_typoScriptNodeValue'])) { $typoScriptArray[$key] = $value['_typoScriptNodeValue']; unset($value['_typoScriptNodeValue']); } $typoScriptArray[$key . '.'] = Tx_Extbase_Utility_TypoScript::convertPlainArrayToTypoScriptArray($value); } else { $typoScriptArray[$key] = $value; } } } return $typoScriptArray; }
/** * @test * @dataProvider convertPlainArrayToTypoScriptArrayTestdata */ public function convertPlainArrayToTypoScriptArray($extbaseTS, $classic) { $converted = Tx_Extbase_Utility_TypoScript::convertPlainArrayToTypoScriptArray($extbaseTS); $this->assertEquals($converted, $classic); }