/** * @return void */ protected function initializeVariants() { $variants = (array) $this->getAllRegisteredVariants(); foreach ($variants as $contentType => $registeredVariantExtensions) { if (TRUE === empty($registeredVariantExtensions)) { continue; } $this->variants[$contentType] = array(); foreach ($registeredVariantExtensions as $extensionKeyOrArray) { $icon = NULL; $versions = array(); if (TRUE === is_array($extensionKeyOrArray) && 3 === count($extensionKeyOrArray)) { list($extensionKey, $labelReference, $icon) = $extensionKeyOrArray; } elseif (TRUE === is_array($extensionKeyOrArray) && 2 === count($extensionKeyOrArray)) { list($extensionKey, $labelReference) = $extensionKeyOrArray; } else { $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKeyOrArray); $labelReference = 'fluidcontent_core.variantLabel'; } $controllerName = 'CoreContent/' . ucfirst($contentType); $paths = $this->getViewConfigurationForExtensionName($extensionKey); $templatePaths = new TemplatePaths($paths); $files = $templatePaths->resolveAvailableTemplateFiles($controllerName); foreach ($files as $file) { $versions[] = basename($file, '.' . TemplatePaths::DEFAULT_FORMAT); } $versions = array_unique($versions); $this->versions[$contentType] = array($extensionKey => $versions); $this->variants[$contentType][] = array($extensionKey, $labelReference, $icon); } } }
/** * @param array $row * @return NULL|string */ public function getExtensionKey(array $row) { if (TRUE === isset($row['name'])) { list($extensionName, , ) = explode('-', $row['name']); } else { list($extensionName, ) = $this->getExtensionKeyAndActionFromUrl(); } return ExtensionNamingUtility::getExtensionKey($extensionName); }
/** * Returns the FluxPackage instance associated with * and possibly existing in $qualifiedExtensionName. * * @param string $qualifiedExtensionName * @return FluxPackageInterface */ public static function getPackage($qualifiedExtensionName) { if (empty($qualifiedExtensionName)) { throw new PackageNotFoundException('Package name cannot be empty'); } $extensionKey = ExtensionNamingUtility::getExtensionKey($qualifiedExtensionName); if (!ExtensionManagementUtility::isLoaded($extensionKey)) { throw new PackageNotFoundException(sprintf('Package name %s (extension key %s) is not loaded', $qualifiedExtensionName, $extensionKey)); } if (!array_key_exists($extensionKey, static::$packages)) { $manifestPath = ExtensionManagementUtility::extPath($extensionKey, 'flux.json'); static::$packages[$extensionKey] = FluxPackage::create($manifestPath)->upcast(); } return static::$packages[$extensionKey]; }
/** * Constructor - takes an array of manifest data in the * same structure as in the manifest JSON file, or an * extension key in which case the expected manifest * is resolved using that and naming convention of the * manifest file. Or takes a full path to the manifest * file in which case the manifest is read from there. * * Note: applies CompatibilityRegistry-resolved versioned * manifest configuration values immediately. * * @param mixed $seedArrayOrExtensionKeyOrManifestPath */ public function __construct($seedArrayOrExtensionKeyOrManifestPath) { if (is_array($seedArrayOrExtensionKeyOrManifestPath)) { $this->manifest = $seedArrayOrExtensionKeyOrManifestPath; } else { $possibleExtensionKey = ExtensionNamingUtility::getExtensionKey($seedArrayOrExtensionKeyOrManifestPath); if (ExtensionManagementUtility::isLoaded($possibleExtensionKey)) { $this->manifest = $this->loadManifestFile(GeneralUtility::getFileAbsFileName(sprintf('EXT:%s/flux.json', $possibleExtensionKey))); } else { $this->manifest = $this->loadManifestFile($seedArrayOrExtensionKeyOrManifestPath); } } if (!empty($this->manifest['compatibility'])) { $scope = $this->manifest['package'] . '/ManifestOverlay'; CompatibilityRegistry::register($scope, $this->manifest['compatibility']); RecursiveArrayUtility::mergeRecursiveOverrule($this->manifest, CompatibilityRegistry::get($scope)); } }
/** * Resolves a list (array) of class names (not instances) of * all classes in files in the specified sub-namespace of the * specified package name. Does not attempt to load the class. * Does not work recursively. * * @param string $packageName * @param string $subNamespace * @param string|NULL $requiredSuffix If specified, class name must use this suffix * @return array */ public function resolveClassNamesInPackageSubNamespace($packageName, $subNamespace, $requiredSuffix = NULL) { $classNames = array(); $extensionKey = ExtensionNamingUtility::getExtensionKey($packageName); $prefix = str_replace('.', '\\', $packageName); $suffix = TRUE === empty($subNamespace) ? '' : str_replace('/', '\\', $subNamespace) . '\\'; $folder = ExtensionManagementUtility::extPath($extensionKey, 'Classes/' . $subNamespace); $files = GeneralUtility::getFilesInDir($folder, 'php'); if (TRUE === is_array($files)) { foreach ($files as $file) { $filename = pathinfo($file, PATHINFO_FILENAME); // include if no required suffix is given or string ends with suffix if (NULL === $requiredSuffix || 1 === preg_match('/' . $requiredSuffix . '$/', $filename)) { $classNames[] = $prefix . '\\' . $suffix . $filename; } } } return $classNames; }
/** * @param string $table * @param Form $form */ protected function processFormForTable($table, Form $form) { $extensionName = $form->getExtensionName(); $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName); $tableConfiguration = self::$tableTemplate; $fields = array(); $labelFields = $form->getOption(Form::OPTION_TCA_LABELS); $enableColumns = array(); foreach ($form->getFields() as $field) { $name = $field->getName(); // note: extracts the TCEforms sub-array from the configuration, as required in TCA. $fields[$name] = array_pop($field->build()); } if (TRUE === $form->getOption(Form::OPTION_TCA_HIDE)) { $enableColumns['disabled'] = 'hidden'; } if (TRUE === $form->getOption(Form::OPTION_TCA_START)) { $enableColumns['start'] = 'starttime'; } if (TRUE === $form->getOption(Form::OPTION_TCA_END)) { $enableColumns['end'] = 'endtime'; } if (TRUE === $form->getOption(Form::OPTION_TCA_FEGROUP)) { $enableColumns['fe_group'] = 'fe_group'; } $tableConfiguration['iconfile'] = ExtensionManagementUtility::extRelPath($extensionKey) . $form->getOption(Form::OPTION_ICON); $tableConfiguration['enablecolumns'] = $enableColumns; $tableConfiguration['title'] = $form->getLabel(); $tableConfiguration['languageField'] = 'sys_language_uid'; $showRecordsFieldList = $this->buildShowItemList($form); $GLOBALS['TCA'][$table] = array('ctrl' => $tableConfiguration, 'interface' => array('showRecordFieldList' => implode(',', array_keys($fields))), 'columns' => $fields, 'types' => array(0 => array('showitem' => $showRecordsFieldList))); if (TRUE === $form->getOption(Form::OPTION_TCA_DELETE)) { $GLOBALS['TCA'][$table]['ctrl']['delete'] = 'deleted'; } if (NULL === $labelFields) { reset($fields); $GLOBALS['TCA'][$table]['ctrl']['label'] = key($fields); } else { $GLOBALS['TCA'][$table]['ctrl']['label'] = array_shift($labelFields); $GLOBALS['TCA'][$table]['ctrl']['label_alt'] = implode(',', $labelFields); } }
/** * Returns the icon for a template * - checks and returns if manually set as option or * - checks and returns Icon if it exists by convention in * EXT:$extensionKey/Resources/Public/Icons/$controllerName/$templateName.(png|gif) * * @param Form $form * @return string|NULL */ public static function getIconForTemplate(Form $form) { if (TRUE === $form->hasOption(Form::OPTION_ICON)) { return $form->getOption(Form::OPTION_ICON); } if (TRUE === $form->hasOption(Form::OPTION_TEMPLATEFILE)) { $extensionKey = ExtensionNamingUtility::getExtensionKey($form->getExtensionName()); $fullTemplatePathAndName = $form->getOption(Form::OPTION_TEMPLATEFILE); $templatePathParts = explode('/', $fullTemplatePathAndName); $templateName = pathinfo(array_pop($templatePathParts), PATHINFO_FILENAME); $controllerName = array_pop($templatePathParts); $allowedExtensions = implode(',', self::$allowedIconTypes); $iconFolder = ExtensionManagementUtility::extPath($extensionKey, 'Resources/Public/Icons/' . $controllerName . '/'); $iconRelFolder = ExtensionManagementUtility::extRelPath($extensionKey) . 'Resources/Public/Icons/' . $controllerName . '/'; $iconPathAndName = $iconFolder . $templateName; $iconMatchPattern = $iconPathAndName . '.{' . $allowedExtensions . '}'; $filesInFolder = TRUE === is_dir($iconFolder) ? glob($iconMatchPattern, GLOB_BRACE) : array(); $iconFile = TRUE === is_array($filesInFolder) && 0 < count($filesInFolder) ? reset($filesInFolder) : NULL; $iconRelPathAndFilename = FALSE === is_null($iconFile) ? $iconRelFolder . str_replace($iconFolder, '', $iconFile) : NULL; return $iconRelPathAndFilename; } return NULL; }
/** * @param string $label * @param string $path * @return NULL|string */ protected function resolveLocalLanguageValueOfLabel($label, $path = NULL) { if ($this->getDisableLocalLanguageLabels()) { return $label; } $name = $this->getName(); $extensionName = $this->extensionName; $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName); if (empty($label) && !ExtensionManagementUtility::isLoaded($extensionKey)) { return $name; } elseif (strpos($label, 'LLL:EXT:') === 0) { return $label; } $relativeFilePath = $this->getLocalLanguageFileRelativePath(); $relativeFilePath = ltrim($relativeFilePath, '/'); $filePrefix = 'LLL:EXT:' . $extensionKey . '/' . $relativeFilePath; if (strpos($label, 'LLL:') === 0) { // Shorthand LLL:name.of.index reference, expand list(, $labelIdentifier) = explode(':', $label, 2); return $filePrefix . ':' . $labelIdentifier; } elseif (!empty($label)) { return $label; } if ($this instanceof Form) { return $filePrefix . ':flux.' . $this->getName(); } $root = $this->getRoot(); $id = $root->getName(); if (empty($path)) { $path = $this->getPath(); } return $filePrefix . ':' . trim('flux.' . $id . '.' . $path, '.'); }
/** * @param string $controllerName * @param string $actionName * @return string|NULL */ protected function getLabelForControllerAction($controllerName, $actionName) { $localLanguageFileRelativePath = $this->getLocalLanguageFileRelativePath(); $extensionName = $this->getControllerExtensionName(); $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName); $pluginName = $this->getPluginName(); $separator = $this->getSeparator(); $controllerClassName = $this->buildExpectedAndExistingControllerClassName($controllerName); $disableLocalLanguageLabels = $this->getDisableLocalLanguageLabels(); $labelPath = strtolower($pluginName . '.' . $controllerName . '.' . $actionName); $hasLocalLanguageFile = file_exists(ExtensionManagementUtility::extPath($extensionKey, $localLanguageFileRelativePath)); $label = $actionName . $separator . $controllerName; if (FALSE === $disableLocalLanguageLabels && TRUE === $hasLocalLanguageFile) { $label = 'LLL:EXT:' . $extensionKey . $localLanguageFileRelativePath . ':' . $labelPath; } elseif (TRUE === method_exists($controllerClassName, $actionName . 'Action') && TRUE === $disableLocalLanguageLabels) { $methodReflection = $this->reflectAction($controllerName, $actionName); $line = array_shift(explode("\n", trim($methodReflection->getDocComment(), "/*\n"))); $line = trim(trim($line), '* '); if (substr($line, 0, 1) !== '@') { $label = $line; } } return $label; }
/** * Gets an array with the default view configuration for the provided * extension key. Maybe overwritten by a sub-service class adding * additional subfolders used by default. * (e.g. EXT:fluidpages can provide "Resources/Private/Templates/Page" * as default templateRootPath) * * @param string $extensionKey * @return array */ protected function getDefaultViewConfigurationForExtensionKey($extensionKey) { $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKey); return array(TemplatePaths::CONFIG_TEMPLATEROOTPATHS => array(0 => 'EXT:' . $extensionKey . '/Resources/Private/Templates/'), TemplatePaths::CONFIG_PARTIALROOTPATHS => array(0 => 'EXT:' . $extensionKey . '/Resources/Private/Partials/'), TemplatePaths::CONFIG_LAYOUTROOTPATHS => array(0 => 'EXT:' . $extensionKey . '/Resources/Private/Layouts/')); }
/** * @param string $extension * @param string $template * @param array $parameters * @return string */ protected function renderOption($extension, $template, array $parameters) { $name = $parameters['itemFormElName']; $value = $parameters['itemFormElValue']; $onChange = 'onclick="if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };"'; $selector = ''; try { $extensionName = ExtensionNamingUtility::getExtensionKey($extension); $paths = $this->configurationService->getPageConfiguration($extensionName); $templatePaths = new TemplatePaths($paths); $templatePathAndFilename = $templatePaths->resolveTemplateFileForControllerAndActionAndFormat('Page', $template); if (FALSE === file_exists($templatePathAndFilename)) { $this->configurationService->message('Missing template file: ' . $templatePathAndFilename, GeneralUtility::SYSLOG_SEVERITY_WARNING); return ''; } $viewContext = new ViewContext($templatePathAndFilename, $extensionName); $viewContext->setTemplatePaths($templatePaths); $viewContext->setSectionName('Configuration'); $form = $this->configurationService->getFormFromTemplateFile($viewContext); if (FALSE === $form instanceof Form) { $this->configurationService->message('Template file ' . $templatePathAndFilename . ' contains an unparsable Form definition', GeneralUtility::SYSLOG_SEVERITY_FATAL); return ''; } if (FALSE === $form->getEnabled()) { $this->configurationService->message('Template file ' . $templatePathAndFilename . ' is disabled by configuration', GeneralUtility::SYSLOG_SEVERITY_NOTICE); return ''; } $thumbnail = MiscellaneousUtility::getIconForTemplate($form); $label = $form->getLabel(); $optionValue = $extension . '->' . $template; $selected = $optionValue == $value ? ' checked="checked"' : ''; $option = '<label style="padding: 0.5em; border: 1px solid #CCC; display: inline-block; vertical-align: bottom; margin: 0 1em 1em 0; cursor: pointer; ' . ($selected ? 'background-color: #DDD;' : '') . '">'; $option .= '<img src="' . $thumbnail . '" alt="' . $label . '" style="margin: 0.5em 0 0.5em 0; max-width: 196px; max-height: 128px;"/><br />'; $option .= '<input type="radio" value="' . $optionValue . '"' . $selected . ' name="' . $name . '" ' . $onChange . ' /> ' . $label; $option .= '</label>'; $selector .= $option . LF; } catch (\RuntimeException $error) { $this->configurationService->debug($error); } return $selector; }
/** * @param string $label * @param string $path * @return NULL|string */ protected function resolveLocalLanguageValueOfLabel($label, $path = NULL) { if (TRUE === $this->getDisableLocalLanguageLabels()) { return $label; } $name = $this->getName(); $root = $this->getRoot(); $extensionName = $this->extensionName; if (FALSE === $root instanceof Form) { $id = 'form'; } else { $id = $root->getName(); } $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName); if (FALSE === empty($label)) { return $this->translateLabelReference($label, $extensionKey); } if (TRUE === empty($extensionKey) || FALSE === ExtensionManagementUtility::isLoaded($extensionKey)) { return $name; } if (TRUE === empty($path)) { if (FALSE === $this instanceof Form) { $path = $this->getPath(); } else { $path = ''; } } $relativeFilePath = $this->getLocalLanguageFileRelativePath(); $relativeFilePath = ltrim($relativeFilePath, '/'); $filePrefix = 'LLL:EXT:' . $extensionKey . '/' . $relativeFilePath; $labelIdentifier = $filePrefix . ':' . trim('flux.' . $id . '.' . $path, '.'); $translated = LocalizationUtility::translate($labelIdentifier, $extensionKey); return NULL !== $translated ? $translated : $labelIdentifier; }
/** * @return string */ public function getExtensionKey() { return ExtensionNamingUtility::getExtensionKey($this->packageName); }
/** * @return void */ protected function initializeOverriddenSettings() { $row = $this->getRecord(); $extensionKey = $this->provider->getExtensionKey($row); $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKey); if (TRUE === isset($this->data['settings']) && TRUE === is_array($this->data['settings'])) { // a "settings." array is defined in the flexform configuration - extract it, use as "settings" in template // as well as the internal $this->settings array as per expected Extbase behavior. $this->settings = RecursiveArrayUtility::merge($this->settings, $this->data['settings']); } if (TRUE === isset($this->settings['useTypoScript']) && TRUE === (bool) $this->settings['useTypoScript']) { // an override shared by all Flux enabled controllers: setting plugin.tx_EXTKEY.settings.useTypoScript = 1 // will read the "settings" array from that location instead - thus excluding variables from the flexform // which are still available as $this->data but no longer available automatically in the template. $this->settings = $this->configurationService->getSettingsForExtensionName($extensionKey); } }
/** * @param array $row * @return string */ public function getExtensionKey(array $row) { $action = $row['tx_fed_fcefile']; if (FALSE !== strpos($action, ':')) { $extensionName = array_shift(explode(':', $action)); } if (FALSE === empty($extensionName)) { $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName); return $extensionKey; } return parent::getExtensionKey($row); }
/** * Renders a Fluid Page Layout file selector * * @param array $parameters * @param mixed $pObj * @return string */ public function renderField(&$parameters, &$pObj) { $name = $parameters['itemFormElName']; $value = $parameters['itemFormElValue']; $availableTemplates = $this->pageService->getAvailablePageTemplateFiles(); if (FALSE === strpos($name, 'tx_fed_controller_action_sub')) { $onChange = 'onclick="if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };"'; } $selector = '<div>'; $typoScript = $this->configurationManager->getTypoScriptSetup(); $hideInheritFieldSiteRoot = (bool) (TRUE === isset($typoScript['plugin.']['tx_fluidpages.']['siteRootInheritance']) ? 1 > $typoScript['plugin.']['tx_fluidpages.']['siteRootInheritance'] : FALSE); $pageIsSiteRoot = (bool) $parameters['row']['is_siteroot']; $forceDisplayInheritSiteRoot = (bool) ('tx_fed_page_controller_action_sub' === $parameters['field']); $forceHideInherit = (bool) (0 === intval($parameters['row']['pid'])); if (FALSE === $pageIsSiteRoot || TRUE === $forceDisplayInheritSiteRoot || FALSE === $hideInheritFieldSiteRoot) { if (FALSE === $forceHideInherit) { $emptyLabel = LocalizationUtility::translate('pages.tx_fed_page_controller_action.default', 'Fluidpages'); $selected = TRUE === empty($value) ? ' checked="checked" ' : NULL; $selector .= '<label>'; $selector .= '<input type="radio" name="' . $name . '" ' . $onChange . '" value="" ' . $selected . '/> ' . $emptyLabel . LF; $selector .= '</label>' . LF; } } foreach ($availableTemplates as $extension => $group) { $extensionKey = ExtensionNamingUtility::getExtensionKey($extension); if (FALSE === ExtensionManagementUtility::isLoaded($extensionKey)) { $groupTitle = ucfirst($extension); } else { $emConfigFile = ExtensionManagementUtility::extPath($extensionKey, 'ext_emconf.php'); require $emConfigFile; $groupTitle = $EM_CONF['']['title']; } $packageLabel = LocalizationUtility::translate('pages.tx_fed_page_package', 'Fluidpages'); $selector .= '<h4 style="clear: both; margin-top: 1em;">' . $packageLabel . ': ' . $groupTitle . '</h4>' . LF; foreach ($group as $template) { try { $paths = $this->configurationService->getPageConfiguration($extension); $extensionName = ExtensionNamingUtility::getExtensionName($extension); $templatePathAndFilename = $this->pageService->expandPathsAndTemplateFileToTemplatePathAndFilename($paths, $template); if (FALSE === file_exists($templatePathAndFilename)) { $this->configurationService->message('Missing template file: ' . $templatePathAndFilename, GeneralUtility::SYSLOG_SEVERITY_WARNING); continue; } $form = $this->configurationService->getFormFromTemplateFile($templatePathAndFilename, 'Configuration', 'form', $paths, $extensionName); if (FALSE === $form instanceof Form) { $this->configurationService->message('Template file ' . $templatePathAndFilename . ' contains an unparsable Form definition', GeneralUtility::SYSLOG_SEVERITY_FATAL); continue; } if (FALSE === $form->getEnabled()) { continue; } $thumbnail = $form->getIcon(); $label = $form->getLabel(); $translatedLabel = LocalizationUtility::translate($label, $extensionName); if (NULL !== $translatedLabel) { $label = $translatedLabel; } $optionValue = $extension . '->' . $template; $selected = $optionValue == $value ? ' checked="checked"' : ''; $option = '<label style="padding: 0.5em; border: 1px solid #CCC; display: inline-block; vertical-align: bottom; margin: 0 1em 1em 0; cursor: pointer; ' . ($selected ? 'background-color: #DDD;' : '') . '">'; $option .= '<img src="' . $thumbnail . '" alt="' . $label . '" style="margin: 0.5em 0 0.5em 0; max-width: 196px; max-height: 128px;"/><br />'; $option .= '<input type="radio" value="' . $optionValue . '"' . $selected . ' name="' . $name . '" ' . $onChange . ' /> ' . $label; $option .= '</label>'; $selector .= $option . LF; } catch (\Exception $error) { $this->configurationService->debug($error); } } } $selector .= '</div>' . LF; unset($pObj); return $selector; }
/** * @return string */ public function getDescription() { $description = $this->description; $translated = NULL; $extensionKey = ExtensionNamingUtility::getExtensionKey($this->extensionName); if (TRUE === empty($description)) { $relativeFilePath = $this->getLocalLanguageFileRelativePath(); $relativeFilePath = ltrim($relativeFilePath, '/'); $filePrefix = 'LLL:EXT:' . $extensionKey . '/' . $relativeFilePath; $description = $filePrefix . ':' . trim('flux.' . $this->id . '.description'); } return $description; }
/** * @param string $extensionName * @return array|NULL */ public function getViewConfigurationForExtensionName($extensionName) { $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName); $configuration = $this->getTypoScriptSubConfiguration(NULL, 'view', $extensionName); if (FALSE === is_array($configuration) || 0 === count($configuration) || TRUE === empty($configuration['templateRootPath'])) { $configuration = array('templateRootPath' => 'EXT:' . $extensionKey . '/Resources/Private/Templates', 'partialRootPath' => 'EXT:' . $extensionKey . '/Resources/Private/Partials', 'layoutRootPath' => 'EXT:' . $extensionKey . '/Resources/Private/Layouts'); } return $configuration; }
/** * @param string $extension * @param string $contentType * @param string $version * @return string */ public function getIconFromVersion($extension, $contentType, $version = NULL) { $extensionKey = ExtensionNamingUtility::getExtensionKey($extension); $templatePathAndFilename = $this->resolveTemplateFileForVariant($extensionKey, $contentType, $extension, $version); $paths = $this->getViewConfigurationForExtensionName($extensionKey); $templatePaths = new TemplatePaths($paths); $viewContext = new ViewContext($templatePathAndFilename, $extensionKey); $viewContext->setTemplatePaths($templatePaths); $viewContext->setSectionName('Configuration'); $form = FluxService::getFormFromTemplateFile($viewContext); if (FALSE === $form instanceof Form) { return ''; } else { return MiscellaneousUtility::getIconForTemplate($form); } }
/** * Fills path arrays with default expected paths * based on package name (converted to extension * key automatically). * * Will replace any currently configured paths. * * @param string $packageName * @return void * @api */ public function fillDefaultsByPackageName($packageName) { $extensionKey = ExtensionNamingUtility::getExtensionKey($packageName); $extensionPath = ExtensionManagementUtility::extPath($extensionKey); $this->setTemplateRootPaths(array($extensionPath . self::DEFAULT_TEMPLATES_DIRECTORY)); $this->setLayoutRootPaths(array($extensionPath . self::DEFAULT_LAYOUTS_DIRECTORY)); $this->setPartialRootPaths(array($extensionPath . self::DEFAULT_PARTIALS_DIRECTORY)); }
/** * @param string $qualifiedExtensionName * @param Form $form * @return void * @throws \RuntimeException */ public function registerModuleBasedOnFluxForm($qualifiedExtensionName, Form $form) { $extensionKey = ExtensionNamingUtility::getExtensionKey($qualifiedExtensionName); $signature = ExtensionNamingUtility::getExtensionSignature($qualifiedExtensionName); $options = $form->getOption('Fluidbackend'); $formId = $form->getName(); $module = 'web'; if (TRUE === isset($options[Constants::FORM_OPTION_MODULE_GROUP])) { $module = $options[Constants::FORM_OPTION_MODULE_GROUP]; } $position = 'before:help'; if (TRUE === isset($options[Constants::FORM_OPTION_MODULE_POSITION])) { $position = $options[Constants::FORM_OPTION_MODULE_POSITION]; } $navigationComponent = ''; if (TRUE === isset($options[Constants::FORM_OPTION_MODULE_PAGE_TREE]) && TRUE === (bool) $options[Constants::FORM_OPTION_MODULE_PAGE_TREE]) { $navigationComponent = 'typo3-pagetree'; } $icon = MiscellaneousUtility::getIconForTemplate($form); if (TRUE === empty($icon)) { $icon = 'EXT:' . $extensionKey . '/ext_icon.gif'; } if (NULL === $this->getResolver()->resolveFluxControllerClassNameByExtensionKeyAndAction($qualifiedExtensionName, 'render', 'Backend')) { throw new \RuntimeException('Attempt to register a Backend controller without an associated BackendController. Extension key: ' . $extensionKey, 1368826271); } $moduleConfiguration = array('access' => 'user,group', 'icon' => $icon, 'labels' => 'LLL:EXT:' . $extensionKey . '/Resources/Private/Language/locallang_module_' . $formId . '.xlf'); if (FALSE === empty($navigationComponent)) { $moduleConfiguration['navigationComponentId'] = $navigationComponent; } $moduleSignature = 'tx_' . $signature . '_' . ucfirst($formId); if (FALSE === isset($GLOBALS['TBE_MODULES'][$module])) { if (FALSE === strpos($position, ':')) { if ('top' === $position) { $temp_TBE_MODULES = array($module => ''); $temp_TBE_MODULES = RecursiveArrayUtility::mergeRecursiveOverrule($temp_TBE_MODULES, $GLOBALS['TBE_MODULES']); } else { $temp_TBE_MODULES = (array) $GLOBALS['TBE_MODULES']; $temp_TBE_MODULES[$module] = ''; } } else { list($command, $relativeKey) = explode(':', $position); foreach ($GLOBALS['TBE_MODULES'] as $key => $val) { if ($key === $relativeKey) { if ('before' === $command) { $temp_TBE_MODULES[$module] = ''; $temp_TBE_MODULES[$key] = $val; } else { $temp_TBE_MODULES[$key] = $val; $temp_TBE_MODULES[$module] = ''; } } else { $temp_TBE_MODULES[$key] = $val; } } } $GLOBALS['TBE_MODULES'] = (array) $temp_TBE_MODULES; // register pseudo-module acting as group header $moduleConfiguration['labels'] = 'LLL:EXT:' . $extensionKey . '/Resources/Private/Language/locallang_modulegroup.xlf'; ExtensionUtility::registerModule($qualifiedExtensionName, $module, '', $position, array('Backend' => 'render,save'), $moduleConfiguration); } // register individual module in group $moduleConfiguration['labels'] = 'LLL:EXT:' . $extensionKey . '/Resources/Private/Language/locallang_module_' . $formId . '.xlf'; ExtensionUtility::registerModule($qualifiedExtensionName, $module, $moduleSignature, $position, array('Backend' => 'render,save'), $moduleConfiguration); }
/** * Get definitions of paths for Page Templates defined in TypoScript * * @param string $extensionName * @return array * @api */ public function getPageConfiguration($extensionName = NULL) { $cacheKey = NULL === $extensionName ? 'pages_global' : 'pages_' . $extensionName; if (TRUE === isset(self::$cache[$cacheKey])) { return self::$cache[$cacheKey]; } if (NULL !== $extensionName && TRUE === empty($extensionName)) { // Note: a NULL extensionName means "fetch ALL defined collections" whereas // an empty value that is not null indicates an incorrect caller. Instead // of returning ALL paths here, an empty array is the proper return value. // However, dispatch a debug message to inform integrators of the problem. $this->message('Template paths have been attempted fetched using an empty value that is NOT NULL in ' . get_class($this) . '. This indicates a potential problem with your TypoScript configuration - a value which is expected to be ' . 'an array may be defined as a string. This error is not fatal but may prevent the affected collection (which cannot ' . 'be identified here) from showing up', GeneralUtility::SYSLOG_SEVERITY_NOTICE); return array(); } if (TYPO3_MODE === 'BE') { // Hack. This is no fun matter, but the TYPO3 BackendConfigurationManager // is incapable of considering how to fetch a page UID from the "editconf" // array which is used when editing a particular page. The result is that // because Flux uses Extbase's resolve methods for TypoScript, the methods // will use the fallback behavior (only root TS templates). Forcibly setting // this GET['id'] should not have a negative effect on other scripts and will // fix the problem - because Extbase will instantly detect and use this ID. // New behaviour has one flaw: editing multiple pages will cause every page // to use the first page's TypoScript settings and therefore page templates - // which could be a problem when editing multiple pages each having own TS. if (TRUE === isset($GLOBALS['SOBE']->editconf['pages'])) { $_GET['id'] = key($GLOBALS['SOBE']->editconf['pages']); } } $newLocation = (array) $this->getTypoScriptSubConfiguration($extensionName, 'collections', 'fluidpages'); $oldLocation = (array) $this->getTypoScriptSubConfiguration($extensionName, 'page', 'fed'); $merged = (array) GeneralUtility::array_merge_recursive_overrule($oldLocation, $newLocation); if (NULL === $extensionName) { $registeredExtensionKeys = Core::getRegisteredProviderExtensionKeys('Page'); foreach ($registeredExtensionKeys as $registeredExtensionKey) { $extensionViewPaths = $this->getPageConfiguration($registeredExtensionKey); if (FALSE === isset($extensionViewPaths['extensionKey'])) { $extensionViewPaths['extensionKey'] = ExtensionNamingUtility::getExtensionKey($registeredExtensionKey); } // preemptive caching; once read here, the cached value is returned when asking for specific extensions later if (FALSE === isset($extensionViewPaths['templateRootPath'])) { $this->sendWarningAboutMissingTemplatePath($registeredExtensionKey); continue; } self::$cache[$registeredExtensionKey] = $extensionViewPaths; $merged[$registeredExtensionKey] = $extensionViewPaths; } } else { $nativeViewLocation = $this->getViewConfigurationForExtensionName($extensionName); if (TRUE === is_array($nativeViewLocation)) { $merged = GeneralUtility::array_merge_recursive_overrule($nativeViewLocation, $merged); } if (FALSE === isset($nativeViewLocation['extensionKey'])) { $merged['extensionKey'] = ExtensionNamingUtility::getExtensionKey($extensionName); } if (FALSE === isset($merged['templateRootPath'])) { $this->sendWarningAboutMissingTemplatePath($extensionName); } } self::$cache[$cacheKey] = $merged; return $merged; }
/** * @return Form[][] */ public function getContentElementFormInstances() { $elements = array(); $allTemplatePaths = $this->getContentConfiguration(); $controllerName = 'Content'; foreach ($allTemplatePaths as $registeredExtensionKey => $templatePathSet) { $files = array(); $extensionKey = TRUE === isset($templatePathSet['extensionKey']) ? $templatePathSet['extensionKey'] : $registeredExtensionKey; $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKey); $templatePaths = new TemplatePaths($templatePathSet); $viewContext = new ViewContext(NULL, $extensionKey); $viewContext->setTemplatePaths($templatePaths); $viewContext->setSectionName('Configuration'); foreach ($templatePaths->getTemplateRootPaths() as $templateRootPath) { $files = GeneralUtility::getAllFilesAndFoldersInPath($files, $templateRootPath . '/' . $controllerName . '/', 'html'); if (0 < count($files)) { foreach ($files as $templateFilename) { $actionName = pathinfo($templateFilename, PATHINFO_FILENAME); $fileRelPath = $actionName . '.html'; $viewContext->setTemplatePathAndFilename($templateFilename); $form = $this->getFormFromTemplateFile($viewContext); if (TRUE === empty($form)) { $this->sendDisabledContentWarning($templateFilename); continue; } if (FALSE === $form->getEnabled()) { $this->sendDisabledContentWarning($templateFilename); continue; } $id = preg_replace('/[\\.\\/]/', '_', $registeredExtensionKey . '/' . $actionName . '.html'); $form->setOption('contentElementId', $registeredExtensionKey . ':' . $fileRelPath); $elements[$registeredExtensionKey][$id] = $form; } } } } return $elements; }
/** * @param array $row * @return array */ public function getTemplatePaths(array $row) { $paths = $this->templatePaths; $extensionKey = $this->getExtensionKey($row); $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKey); if (FALSE === is_array($paths)) { $extensionKey = $this->getExtensionKey($row); if (FALSE === empty($extensionKey) && TRUE === ExtensionManagementUtility::isLoaded($extensionKey)) { $paths = $this->configurationService->getViewConfigurationForExtensionName($extensionKey); } } if (NULL !== $paths && FALSE === is_array($paths)) { $this->configurationService->message('Template paths resolved for "' . $extensionKey . '" was not an array.', GeneralUtility::SYSLOG_SEVERITY_WARNING); $paths = NULL; } if (NULL === $paths) { $extensionKey = $this->getExtensionKey($row); if (FALSE === empty($extensionKey) && TRUE === ExtensionManagementUtility::isLoaded($extensionKey)) { $paths = array(ExtensionManagementUtility::extPath($extensionKey, 'Resources/Private/Templates/'), ExtensionManagementUtility::extPath($extensionKey, 'Resources/Private/Partials/'), ExtensionManagementUtility::extPath($extensionKey, 'Resources/Private/Layouts/')); } else { $paths = array(); } } if (TRUE === is_array($paths)) { $paths = PathUtility::translatePath($paths); } return $paths; }
/** * @test */ public function testGetExtensionKeyWithVendorName() { $result = ExtensionNamingUtility::getExtensionKey('FT3.FooExt'); $this->assertSame('foo_ext', $result); }
/** * @param array $row * @return string */ public function getExtensionKey(array $row) { $controllerExtensionKey = $this->getControllerExtensionKeyFromRecord($row); if (FALSE === empty($controllerExtensionKey)) { return ExtensionNamingUtility::getExtensionKey($controllerExtensionKey); } return parent::getExtensionKey($row); }
/** * @param array $row * @return array */ public function getTemplatePaths(array $row) { $paths = $this->templatePaths; if (FALSE === is_array($paths)) { $extensionKey = $this->getExtensionKey($row); $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKey); if (FALSE === empty($extensionKey)) { $paths = $this->configurationService->getViewConfigurationForExtensionName($extensionKey); } } if (TRUE === is_array($paths)) { $paths = PathUtility::translatePath($paths); } return $paths; }
/** * @param string $extensionName * @return array|NULL */ public function getBackendViewConfigurationForExtensionName($extensionName) { $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName); $configuration = $this->getTypoScriptSubConfiguration(NULL, 'view', $extensionKey, 'module'); return $configuration; }
/** * @param array $row * @return array */ public function getTemplatePaths(array $row) { $paths = parent::getTemplatePaths($row); $variant = $this->getVariant($row); if (FALSE === empty($variant)) { $extensionKey = ExtensionNamingUtility::getExtensionKey($variant); if (FALSE === empty($extensionKey)) { $overlayPaths = $this->configurationService->getViewConfigurationForExtensionName($extensionKey); $paths = array_merge_recursive($paths, $overlayPaths); } } return $paths; }
/** * @return Form[][] */ public function getContentElementFormInstances() { $elements = array(); $allTemplatePaths = $this->getContentConfiguration(); foreach ($allTemplatePaths as $key => $templatePathSet) { $key = trim($key, '.'); $extensionKey = TRUE === isset($templatePathSet['extensionKey']) ? $templatePathSet['extensionKey'] : $key; $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKey); $paths = array('templateRootPath' => TRUE === isset($templatePathSet['templateRootPath']) ? $templatePathSet['templateRootPath'] : 'EXT:' . $extensionKey . '/Resources/Private/Templates/', 'layoutRootPath' => TRUE === isset($templatePathSet['layoutRootPath']) ? $templatePathSet['layoutRootPath'] : 'EXT:' . $extensionKey . '/Resources/Private/Layouts/', 'partialRootPath' => TRUE === isset($templatePathSet['partialRootPath']) ? $templatePathSet['partialRootPath'] : 'EXT:' . $extensionKey . '/Resources/Private/Partials/'); $paths = PathUtility::translatePath($paths); $templateRootPath = rtrim($paths['templateRootPath'], '/') . '/'; if (TRUE === file_exists($templateRootPath . 'Content/')) { $templateRootPath = $templateRootPath . 'Content/'; } $templateRootPathLength = strlen($templateRootPath); $files = array(); $files = GeneralUtility::getAllFilesAndFoldersInPath($files, $templateRootPath, 'html'); if (0 < count($files)) { foreach ($files as $templateFilename) { $fileRelPath = substr($templateFilename, $templateRootPathLength); $form = $this->getFormFromTemplateFile($templateFilename, 'Configuration', 'form', $paths, $extensionKey); if (TRUE === empty($form)) { $this->sendDisabledContentWarning($templateFilename); continue; } if (FALSE === $form->getEnabled()) { $this->sendDisabledContentWarning($templateFilename); continue; } $id = $extensionKey . '_' . preg_replace('/[\\.\\/]/', '_', $fileRelPath); $form->setOption('contentElementId', $extensionKey . ':' . $fileRelPath); $elements[$extensionKey][$id] = $form; } } } return $elements; }