diff --git a/Classes/Backend/Preview.php b/Classes/Backend/Preview.php index 4de0e68..e7bdb43 100644 --- a/Classes/Backend/Preview.php +++ b/Classes/Backend/Preview.php @@ -22,6 +22,7 @@ namespace SkillDisplay\Typo3Extension\Backend; */ use SkillDisplay\PHPToolKit\Api\Skill; +use SkillDisplay\PHPToolKit\Api\SkillSet; use TYPO3\CMS\Backend\View\PageLayoutView; use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -33,10 +34,17 @@ class Preview implements PageLayoutViewDrawItemHookInterface */ protected $skillApi; + /** + * @var SkillSet + */ + private $skillSetApi; + public function __construct( - Skill $skillApi + Skill $skillApi, + SkillSet $skillSetApi ) { $this->skillApi = $skillApi; + $this->skillSetApi = $skillSetApi; } /** @@ -50,9 +58,36 @@ class Preview implements PageLayoutViewDrawItemHookInterface array &$row ) { $row['skills'] = []; + $row['skillSets'] = []; + + if ($row['skilldisplay_skills'] != '') { + $row = $this->addSkills($row); + } + + if ($row['skilldisplay_skillset'] > 0) { + $row = $this->addSkillSets($row); + } + } + + private function addSkills(array $row): array + { $skills = GeneralUtility::intExplode(',', $row['skilldisplay_skills'], true); + foreach ($skills as $skillId) { $row['skills'][] = $this->skillApi->getById($skillId); } + + return $row; + } + + private function addSkillSets(array $row): array + { + $skillSets = GeneralUtility::intExplode(',', $row['skilldisplay_skillset'], true); + + foreach ($skillSets as $skillSetId) { + $row['skillSets'][] = $this->skillSetApi->getById($skillSetId); + } + + return $row; } } diff --git a/Classes/Frontend/DataProcessing/SkillSets.php b/Classes/Frontend/DataProcessing/SkillSets.php new file mode 100644 index 0000000..7adc54e --- /dev/null +++ b/Classes/Frontend/DataProcessing/SkillSets.php @@ -0,0 +1,63 @@ + + * + * 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. + */ + +use SkillDisplay\PHPToolKit\Api\SkillSet; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; +use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; + +class SkillSets implements DataProcessorInterface +{ + /** + * @var SkillSet + */ + protected $skillSetApi; + + public function __construct( + SkillSet $skillSetApi + ) { + $this->skillSetApi = $skillSetApi; + } + + public function process( + ContentObjectRenderer $cObj, + array $contentObjectConfiguration, + array $processorConfiguration, + array $processedData + ) { + $as = $cObj->stdWrapValue('as', $processorConfiguration, 'skillSets'); + $skillSetIds = GeneralUtility::intExplode( + ',', + $cObj->stdWrapValue('skillSets', $processorConfiguration, ''), + true + ); + $skillSets = []; + + foreach ($skillSetIds as $skillSetId) { + $skillSets[] = $this->skillSetApi->getById($skillSetId); + } + + $processedData[$as] = $skillSets; + return $processedData; + } +} diff --git a/Classes/ViewHelpers/Verification/ButtonViewHelper.php b/Classes/ViewHelpers/Verification/ButtonViewHelper.php index 352397a..d2a44eb 100644 --- a/Classes/ViewHelpers/Verification/ButtonViewHelper.php +++ b/Classes/ViewHelpers/Verification/ButtonViewHelper.php @@ -22,33 +22,19 @@ namespace SkillDisplay\Typo3Extension\ViewHelpers\Verification; */ use SkillDisplay\PHPToolKit\Verification\Link; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; -use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; +use SkillDisplay\Typo3Extension\ViewHelpers\VerificationViewHelper; use TYPO3\CMS\Core\Utility\GeneralUtility; -class ButtonViewHelper extends AbstractViewHelper +class ButtonViewHelper extends VerificationViewHelper { - use CompileWithRenderStatic; - - protected $escapeOutput = false; - - public function initializeArguments() + protected static function verificationHtml(array $arguments): string { - $this->registerArgument('skill', 'integer', 'ID of the skill.', true); - $this->registerArgument('type', 'string', 'Type of verification', false, 'self'); - } - - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { /** @var Link $link */ $link = GeneralUtility::makeInstance(Link::class); return $link->getVerificationButton( $arguments['type'], - $arguments['skill'] + static::getId($arguments), + static::getType($arguments) ); } } diff --git a/Classes/ViewHelpers/Verification/UrlViewHelper.php b/Classes/ViewHelpers/Verification/UrlViewHelper.php index 5ad21f3..fb27f82 100644 --- a/Classes/ViewHelpers/Verification/UrlViewHelper.php +++ b/Classes/ViewHelpers/Verification/UrlViewHelper.php @@ -22,33 +22,19 @@ namespace SkillDisplay\Typo3Extension\ViewHelpers\Verification; */ use SkillDisplay\PHPToolKit\Verification\Link; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; -use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; +use SkillDisplay\Typo3Extension\ViewHelpers\VerificationViewHelper; use TYPO3\CMS\Core\Utility\GeneralUtility; -class UrlViewHelper extends AbstractViewHelper +class UrlViewHelper extends VerificationViewHelper { - use CompileWithRenderStatic; - - protected $escapeOutput = false; - - public function initializeArguments() + protected static function verificationHtml(array $arguments): string { - $this->registerArgument('skill', 'integer', 'ID of the skill.', true); - $this->registerArgument('type', 'string', 'Type of verification', false, 'self'); - } - - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { /** @var Link $link */ $link = GeneralUtility::makeInstance(Link::class); return $link->getVerificationLink( $arguments['type'], - $arguments['skill'] + static::getId($arguments), + static::getType($arguments) ); } } diff --git a/Classes/ViewHelpers/VerificationViewHelper.php b/Classes/ViewHelpers/VerificationViewHelper.php new file mode 100644 index 0000000..129a4eb --- /dev/null +++ b/Classes/ViewHelpers/VerificationViewHelper.php @@ -0,0 +1,92 @@ + + * + * 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. + */ + +use SkillDisplay\PHPToolKit\Verification\Link; +use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; +use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +abstract class VerificationViewHelper extends AbstractViewHelper +{ + use CompileWithRenderStatic; + + protected $escapeOutput = false; + + public function initializeArguments() + { + $this->registerArgument('skill', 'integer', 'ID of the Skill.'); + $this->registerArgument('skillSet', 'integer', 'ID of the SkillSet.'); + $this->registerArgument('type', 'string', 'Type of verification', false, 'self'); + } + + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + static::validateIds($arguments); + + return static::verificationHtml($arguments); + } + + abstract protected static function verificationHtml(array $arguments): string; + + /** + * @return void + */ + protected static function validateIds(array $arguments) + { + if ( + isset($arguments['skill']) && $arguments['skill'] !== '' + && isset($arguments['skillSet']) && $arguments['skillSet'] !== '' + ) { + throw new \Exception('Can only handle skill or skillSet not both.', 1600775604); + } + + if ( + (isset($arguments['skill']) === false || $arguments['skill'] === '') + && (isset($arguments['skillSet']) === false || $arguments['skillSet'] === '') + ) { + throw new \Exception('Either needs skill or skillSet, none given.', 1600775604); + } + } + + protected static function getId(array $arguments): int + { + if (static::getType($arguments) === Link::SKILL) { + return $arguments['skill']; + } + + return $arguments['skillSet']; + } + + protected static function getType(array $arguments): string + { + if (isset($arguments['skill']) && $arguments['skill'] !== '') { + return Link::SKILL; + } + + return Link::SKILL_SET; + } +} diff --git a/Configuration/PageTSconfig/Mod/Wizards/Skillset.tsconfig b/Configuration/PageTSconfig/Mod/Wizards/Skillset.tsconfig new file mode 100644 index 0000000..3e1a869 --- /dev/null +++ b/Configuration/PageTSconfig/Mod/Wizards/Skillset.tsconfig @@ -0,0 +1,15 @@ +mod { + wizards.newContentElement.wizardItems.skilldisplay { + elements { + skilldisplay_skillset { + iconIdentifier = skilldisplay-skillset + title = LLL:EXT:skilldisplay/Resources/Private/Language/locallang_tca.xlf:tt_content.skilldisplay_skillset + description = LLL:EXT:skilldisplay/Resources/Private/Language/locallang_be.xlf:newContentElement.skilldisplay.skillset.description + tt_content_defValues { + CType = skilldisplay_skillset + } + } + } + } + web_layout.tt_content.preview.skilldisplay_skillset = EXT:skilldisplay/Resources/Private/Templates/Backend/ContentElements/Skillset.html +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 0809d6f..a3a5c41 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -24,6 +24,10 @@ services: arguments: $settings: '@skilldisplay.settings' + SkillDisplay\PHPToolKit\Api\SkillSet: + arguments: + $settings: '@skilldisplay.settings' + SkillDisplay\PHPToolKit\Verification\Link: public: true arguments: diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index 6925f5e..bb1c043 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -22,6 +22,16 @@ 'size' => 10, ], ], + 'skilldisplay_skillset' => [ + 'exclude' => 1, + 'label' => $languagePath . 'skilldisplay_skillset', + 'description' => $languagePath . 'skilldisplay_skillset.description', + 'config' => [ + 'type' => 'input', + 'eval' => 'int,required', + 'size' => 10, + ], + ], ], ]); })('skilldisplay', 'tt_content'); diff --git a/Configuration/TCA/Overrides/tt_content_skillset.php b/Configuration/TCA/Overrides/tt_content_skillset.php new file mode 100644 index 0000000..2f3f516 --- /dev/null +++ b/Configuration/TCA/Overrides/tt_content_skillset.php @@ -0,0 +1,46 @@ + [ + 'typeicon_classes' => [ + $contentType => 'skilldisplay-skillset', + ], + ], + 'types' => [ + $contentType => [ + 'showitem' => implode(',', [ + '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general', + '--palette--;;general', + 'skilldisplay_skillset', + '--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance', + '--palette--;;frames', + '--palette--;;appearanceLinks', + '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language', + '--palette--;;language', + '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access', + '--palette--;;hidden', + '--palette--;;access', + '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories', + 'categories', + '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:notes', + 'rowDescription', + '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended', + ]), + ], + ], + ]); + + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem( + $tableName, + 'CType', + [ + $languagePath . $contentType, + $contentType, + 'skilldisplay-skillset', + 'skilldisplay' + ] + ); +})('skilldisplay', 'tt_content', 'skilldisplay_skillset'); diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index c7ec84d..e87cb76 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -9,3 +9,15 @@ tt_content.skilldisplay_skills { } } } + +tt_content.skilldisplay_skillset = < lib.contentElement +tt_content.skilldisplay_skillset { + templateName = SkillDisplaySkillSet + + dataProcessing { + 10 = SkillDisplay\Typo3Extension\Frontend\DataProcessing\SkillSets + 10 { + skillSets.field = skilldisplay_skillset + } + } +} diff --git a/Resources/Private/Language/locallang_be.xlf b/Resources/Private/Language/locallang_be.xlf index 6f627d9..8fe73a8 100644 --- a/Resources/Private/Language/locallang_be.xlf +++ b/Resources/Private/Language/locallang_be.xlf @@ -9,6 +9,9 @@ Renders one or multiple skills. + + Renders one skillset. + SkillDisplay diff --git a/Resources/Private/Language/locallang_tca.xlf b/Resources/Private/Language/locallang_tca.xlf index 152a116..2d31729 100644 --- a/Resources/Private/Language/locallang_tca.xlf +++ b/Resources/Private/Language/locallang_tca.xlf @@ -9,6 +9,12 @@ Comma separated list of UIDs. + + SkillDisplay: SkillSet + + + UID of SkillSet + SkillDisplay diff --git a/Resources/Private/Templates/Backend/ContentElements/Skillset.html b/Resources/Private/Templates/Backend/ContentElements/Skillset.html new file mode 100644 index 0000000..0eef70b --- /dev/null +++ b/Resources/Private/Templates/Backend/ContentElements/Skillset.html @@ -0,0 +1,18 @@ + + + + + + + {skillSet.name} + + + + + diff --git a/Resources/Private/Templates/ContentElements/SkillDisplaySkillSet.html b/Resources/Private/Templates/ContentElements/SkillDisplaySkillSet.html new file mode 100644 index 0000000..965e5ad --- /dev/null +++ b/Resources/Private/Templates/ContentElements/SkillDisplaySkillSet.html @@ -0,0 +1,13 @@ + + + + + {skillSet.name} + {skillSet.description -> f:format.html()} + + + + + diff --git a/Resources/Public/Icons/skillset.png b/Resources/Public/Icons/skillset.png new file mode 100644 index 0000000..91aee2c Binary files /dev/null and b/Resources/Public/Icons/skillset.png differ diff --git a/ext_localconf.php b/ext_localconf.php index 442a883..85c9815 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -7,6 +7,7 @@ $icons = [ 'skill', + 'skillset', ]; $iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( \TYPO3\CMS\Core\Imaging\IconRegistry::class diff --git a/ext_tables.sql b/ext_tables.sql index 42244d0..20a931a 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -1,3 +1,4 @@ CREATE TABLE tt_content ( skilldisplay_skills TEXT, + skilldisplay_skillset int(11) unsigned DEFAULT '0' NOT NULL, );
{skillSet.description -> f:format.html()}