Skip to content

Commit

Permalink
Merge pull request #49 from maikschneider/configure-markup
Browse files Browse the repository at this point in the history
feat: make icon markup configurable
  • Loading branch information
maikschneider authored Jun 14, 2024
2 parents 18474ab + 331936b commit 5c30024
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
5 changes: 5 additions & 0 deletions Classes/Provider/AbstractIconProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public function __construct($options)
$this->options = $options;
}

public function getOptions(): array
{
return $this->options;
}

public function getTitle(): string
{
return $this->title;
Expand Down
1 change: 1 addition & 0 deletions Classes/Utility/HelperUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getModalTabs(): array
$tab['id'] = $provider->getId();
$tab['title'] = $provider->getTitle();
$tab['folders'] = $provider->getIcons();
$tab['markup'] = $provider->getOptions()['markup'] ?? '';

$tabs[] = $tab;
}
Expand Down
23 changes: 19 additions & 4 deletions Classes/ViewHelpers/IconViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Blueways\BwIcons\ViewHelpers;

use DOMDocument;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
Expand Down Expand Up @@ -43,9 +44,17 @@ public static function renderStatic(
return '<img ' . $attrString . ' />';
}

$attributes['class'] = $arguments['icon'];
$attrString = static::concatAttributes($attributes);
return '<i ' . $attrString . '></i>';
$markup = $arguments['markup'] ?: '<i class="###ICON###"></i>';
$markup = str_replace('###ICON###', $arguments['icon'], $markup);

$doc = new DOMDocument();
$doc->loadHTML($markup, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$element = $doc->getElementsByTagName('*')->item(0);
foreach ($attributes as $attributeName => $attributeValue) {
$element->setAttribute($attributeName, $attributeValue);
}

return $doc->saveHTML() ?: '';
}

protected static function concatAttributes(array $attributes): string
Expand All @@ -59,7 +68,13 @@ public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('icon', 'string', 'The icon name', true);
$this->registerArgument('provider', 'string', 'PageTS did of the used IconProvider', false);
$this->registerArgument(
'markup',
'string',
'Markup of the icon. Use ###ICON### as placeholder for the icon name.',
false,
''
);
$this->registerArgument(
'additionalAttributes',
'array',
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ mod.tx_bwicons {
icomoon {
title = Icomoon
file = https://i.icomoon.io/public/b23ec64zea/Project/style.css
# optional: adjust markup in backend wizard
# defaults to <i class="###ICON###"></i>
markup = <span class="my-custom-class ###ICON###"></span>
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Template/Modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h1>
<f:variable name="cssClassName">thumbnail--white</f:variable>
</f:if>
<a href="#" class="thumbnail {cssClassName}">
<bw:icon icon="{icon}"/>
<bw:icon icon="{icon}" markup="{tab.markup}" />
</a>
</div>
</f:for>
Expand Down
23 changes: 13 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}
},
"config": {
"sort-packages": true,
"vendor-dir": "vendor",
"allow-plugins": {
"typo3/cms-composer-installers": true,
Expand All @@ -30,9 +31,14 @@
}
],
"license": [
"GPL-3.0-or-later"
"GPL-2.0-or-later"
],
"require-dev": {
"bk2k/bootstrap-package": "dev-master",
"clue/phar-composer": "^1.0",
"friendsofphp/php-cs-fixer": "^3.12",
"phpmd/phpmd": "^2.13.0",
"saschaegerer/phpstan-typo3": "^1.8",
"typo3/cms-backend": "^12.0",
"typo3/cms-belog": "^12.0",
"typo3/cms-beuser": "^12.0",
Expand All @@ -59,11 +65,6 @@
"typo3/cms-seo": "^12.0",
"typo3/cms-setup": "^12.0",
"typo3/cms-tstemplate": "^12.0",
"bk2k/bootstrap-package": "dev-master",
"clue/phar-composer": "^1.0",
"friendsofphp/php-cs-fixer": "^3.12",
"saschaegerer/phpstan-typo3": "^1.8",
"phpmd/phpmd": "^2.13.0",
"typo3/testing-framework": "^8.0"
},
"autoload": {
Expand All @@ -89,10 +90,12 @@
},
"require": {
"php": "^8.0",
"sabberworm/php-css-parser": "8.4.0",
"ext-simplexml": "*",
"ext-dom": "*",
"ext-json": "*",
"typo3/cms-core": "^12.0",
"phenx/php-font-lib": "0.5.4"
"ext-libxml": "*",
"ext-simplexml": "*",
"phenx/php-font-lib": "0.5.4",
"sabberworm/php-css-parser": "8.4.0",
"typo3/cms-core": "^12.4"
}
}

0 comments on commit 5c30024

Please sign in to comment.