diff --git a/Classes/ViewHelpers/Format/IdViewHelper.php b/Classes/ViewHelpers/Format/IdViewHelper.php new file mode 100644 index 0000000..ee7deb6 --- /dev/null +++ b/Classes/ViewHelpers/Format/IdViewHelper.php @@ -0,0 +1,59 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +namespace DanielSiepmann\DsSite\ViewHelpers\Format; + +use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; +use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +/** + * Formats a given string to be a valid HTML id attribute value. + */ +class IdViewHelper extends AbstractViewHelper +{ + use CompileWithContentArgumentAndRenderStatic; + + public function initializeArguments() + { + $this->registerArgument('value', 'string', 'string to format'); + } + + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + $value = $renderChildrenClosure(); + if (!is_string($value) && !(is_object($value) && method_exists($value, '__toString'))) { + return $value; + } + $value = (string)$value; + $value = str_replace(' ', '_', $value); + $value = preg_replace('#\W#', '', $value); + $value = GeneralUtility::underscoredToUpperCamelCase($value); + $value = lcfirst($value); + return $value; + } +} diff --git a/Resources/Private/Partials/ContentElements/Header.html b/Resources/Private/Partials/ContentElements/Header.html index 4b189df..4675132 100644 --- a/Resources/Private/Partials/ContentElements/Header.html +++ b/Resources/Private/Partials/ContentElements/Header.html @@ -1,7 +1,7 @@ - + - {header} + {header} diff --git a/Resources/Private/Templates/Page/BlogPost.html b/Resources/Private/Templates/Page/BlogPost.html index 3afd09a..c1594fa 100644 --- a/Resources/Private/Templates/Page/BlogPost.html +++ b/Resources/Private/Templates/Page/BlogPost.html @@ -54,7 +54,7 @@
  • - {contentEntry.data.header} + {contentEntry.data.header}
  • diff --git a/ext_localconf.php b/ext_localconf.php index 4fb81d4..e6a2141 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -14,6 +14,15 @@ ], ], ], + 'SYS' => [ + 'fluid' => [ + 'namespaces' => [ + 'f' => [ + 99 => 'DanielSiepmann\\DsSite\\ViewHelpers', + ], + ], + ], + ], ]); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig( "@import 'EXT:ds_site/Configuration/UserTSconfig/*.tsconfig'"