/** * 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; }