/** * Builds a single Wizard item (one FCE) based on the * tab id, element id, configuration array and special * template identity (groupName:Relative/Path/File.html) * * @param string $tabId * @param string $id * @param Form $form * @param string $templateFileIdentity * @return string */ protected function buildWizardTabItem($tabId, $id, $form, $templateFileIdentity) { if (TRUE === method_exists('FluidTYPO3\\Flux\\Utility\\MiscellaneousUtility', 'getIconForTemplate')) { $icon = MiscellaneousUtility::getIconForTemplate($form); $icon = $icon ? $icon : $this->defaultIcon; } else { $icon = $this->defaultIcon; } $description = $form->getDescription(); if (0 === strpos($icon, '../')) { $icon = substr($icon, 2); } if ('/' === $icon[0]) { $icon = realpath(PATH_site . $icon); } if (TRUE === file_exists($icon) && TRUE === method_exists('FluidTYPO3\\Flux\\Utility\\MiscellaneousUtility', 'createIcon')) { $icon = '../..' . MiscellaneousUtility::createIcon($icon, $this->extConf['iconWidth'], $this->extConf['iconHeight']); } return sprintf(' mod.wizards.newContentElement.wizardItems.%s.elements.%s { icon = %s title = %s description = %s tt_content_defValues { CType = fluidcontent_content tx_fed_fcefile = %s } } ', $tabId, $id, $icon, $form->getLabel(), $description, $templateFileIdentity); }
/** * @param array $parameters * @param PageLayoutView|DatabaseRecordList $caller * @return string */ public function addSubIcon(array $parameters, $caller = NULL) { $this->attachAssets(); list($table, $uid, $record) = $parameters; $icon = NULL; if (NULL !== $caller) { $record = NULL === $record && 0 < $uid ? BackendUtility::getRecord($table, $uid) : $record; $cacheIdentity = $table . $uid . sha1(serialize($record)); // filter 1: icon must not already be cached and both record and caller must be provided. if (TRUE === $this->cache->has($cacheIdentity)) { $icon = $this->cache->get($cacheIdentity); } elseif (NULL !== $record) { $field = $this->detectFirstFlexTypeFieldInTableFromPossibilities($table, array_keys($record)); // filter 2: table must have one field defined as "flex" and record must include it. if (NULL !== $field && TRUE === isset($record[$field])) { // we check the cache here because at this point, the cache key is decidedly // unique and we have not yet consulted the (potentially costly) Provider. $provider = $this->fluxService->resolvePrimaryConfigurationProvider($table, $field, $record); // filter 3: a Provider must be resolved for the record. if (NULL !== $provider) { $form = $provider->getForm((array) $record); if (NULL !== $form) { $icon = MiscellaneousUtility::getIconForTemplate($form); if (NULL !== $icon) { $label = trim($form->getLabel()); $icon = '<img width="16" height="16" src="' . $icon . '" alt="' . $label . '" title="' . $label . '" class="" />'; $icon = sprintf($this->templates['iconWrapper'], $icon); } } } } $this->cache->set($cacheIdentity, $icon); } } return $icon; }
/** * @param array $configuration * @param string $groupLabel * @param mixed $value * @return string */ protected function renderOptionGroup(array $configuration, $groupLabel, $value) { $optionGroup = ''; foreach ($configuration as $form) { /** @var Form $form */ $optionValue = $form->getOption('contentElementId'); $selected = $optionValue === $value ? ' selected="selected"' : ''; $label = $form->getLabel(); $icon = MiscellaneousUtility::getIconForTemplate($form); $label = 0 === strpos($label, 'LLL:') ? $GLOBALS['LANG']->sL($label) : $label; $valueString = htmlspecialchars($optionValue); $labelString = htmlspecialchars($label); $optionGroup .= sprintf($this->templates['option'], $icon, $valueString, $selected, $labelString) . LF; } return sprintf($this->templates['optgroup'], htmlspecialchars($groupLabel), $optionGroup); }
/** * @test */ public function returnFalseResultIfNoTemplateAndNoIconOptionIsSet() { $form = $this->getFormInstance(); $icon = MiscellaneousUtility::getIconForTemplate($form); $this->assertNull($icon); }
/** * Builds a single Wizard item (one FCE) based on the * tab id, element id, configuration array and special * template identity (groupName:Relative/Path/File.html) * * @param string $tabId * @param string $id * @param Form $form * @param string $templateFileIdentity * @return string */ protected function buildWizardTabItem($tabId, $id, $form, $templateFileIdentity) { if (TRUE === method_exists('FluidTYPO3\\Flux\\Utility\\MiscellaneousUtility', 'getIconForTemplate')) { $icon = MiscellaneousUtility::getIconForTemplate($form); $icon = $icon ? $icon : $this->defaultIcon; } else { $icon = $this->defaultIcon; } $description = $form->getDescription(); if (0 === strpos($icon, '../')) { $icon = substr($icon, 2); } $iconIdentifier = NULL; if (TRUE === method_exists('FluidTYPO3\\Flux\\Utility\\MiscellaneousUtility', 'createIcon')) { if ('/' === $icon[0]) { $icon = realpath(PATH_site . $icon); } if (TRUE === file_exists($icon) && TRUE === is_file($icon)) { $extension = pathinfo($icon, PATHINFO_EXTENSION); switch (strtolower($extension)) { case 'svg': case 'svgz': $iconProvider = SvgIconProvider::class; break; default: $iconProvider = BitmapIconProvider::class; } $iconIdentifier = 'fluidcontent-' . $id; $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class); $iconRegistry->registerIcon($iconIdentifier, $iconProvider, array('source' => $icon)); } } $defaultValues = array(); if ($form->hasOption(Form::OPTION_DEFAULT_VALUES)) { foreach ($form->getOption(Form::OPTION_DEFAULT_VALUES) as $key => $value) { $defaultValues[] = $key . ' = ' . $value; } } return sprintf(' mod.wizards.newContentElement.wizardItems.%s.elements.%s { iconIdentifier = %s title = %s description = %s tt_content_defValues { %s CType = fluidcontent_content tx_fed_fcefile = %s } } ', $tabId, $id, $iconIdentifier, $form->getLabel(), $description, implode(chr(10), $defaultValues), $templateFileIdentity); }
/** * @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 $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); } }
/** * @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); }
/** * Builds a single Wizard item (one FCE) based on the * tab id, element id, configuration array and special * template identity (groupName:Relative/Path/File.html) * * @param string $tabId * @param string $id * @param Form $form * @param string $templateFileIdentity * @return string */ protected function buildWizardTabItem($tabId, $id, $form, $templateFileIdentity) { $icon = MiscellaneousUtility::getIconForTemplate($form); $description = $form->getDescription(); $iconFileRelativePath = $icon ? $icon : $this->defaultIcon; return sprintf(' mod.wizards.newContentElement.wizardItems.%s.elements.%s { icon = %s title = %s description = %s tt_content_defValues { CType = fluidcontent_content tx_fed_fcefile = %s } } ', $tabId, $id, $iconFileRelativePath, $form->getLabel(), $description, $templateFileIdentity); }
/** * @param Form $form * @param array $parameters * @return string */ protected function renderOption(Form $form, array $parameters) { $name = $parameters['itemFormElName']; $value = $parameters['itemFormElValue']; $fieldTSConfig = $parameters['fieldTSConfig']; $keepItems = isset($fieldTSConfig['keepItems']) ? explode(',', $fieldTSConfig['keepItems']) : NULL; $removeItems = isset($fieldTSConfig['removeItems']) ? explode(',', $fieldTSConfig['removeItems']) : NULL; $default = isset($fieldTSConfig['default']) ? $fieldTSConfig['default'] : NULL; $onChange = 'onclick="if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };"'; $selector = ''; try { $extension = $form->getExtensionName(); $thumbnail = MiscellaneousUtility::getIconForTemplate($form); $template = pathinfo($form->getOption(Form::OPTION_TEMPLATEFILE), PATHINFO_FILENAME); $label = $form->getLabel(); $optionValue = $extension . '->' . lcfirst($template); $selected = FALSE; if (TRUE === empty($value)) { if (FALSE === empty($default)) { $selected = $optionValue == $default ? ' checked="checked"' : NULL; } } else { $selected = $optionValue == $value ? ' checked="checked"' : NULL; } $option = $this->getField($selected, $thumbnail, $label, $optionValue, $name, $onChange); if (FALSE === empty($keepItems)) { if (TRUE === in_array($optionValue, $keepItems)) { $selector .= $option . LF; } } elseif (FALSE === empty($removeItems)) { if (FALSE === in_array($optionValue, $removeItems)) { $selector .= $option . LF; } } else { $selector .= $option . LF; } } catch (\RuntimeException $error) { $this->configurationService->debug($error); } return $selector; }
/** * @param Form $form * @param array $parameters * @return string */ protected function renderOption(Form $form, 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 { $extension = $form->getExtensionName(); $thumbnail = MiscellaneousUtility::getIconForTemplate($form); $template = pathinfo($form->getOption(Form::OPTION_TEMPLATEFILE), PATHINFO_FILENAME); $formLabel = $form->getLabel(); if (strpos($formLabel, 'LLL:') === 0) { $label = LocalizationUtility::translate($formLabel, $extension); } else { $label = $formLabel; } $optionValue = $extension . '->' . lcfirst($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; }