From e9671122772450d0741c289a482704eb8050e938 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 22 Sep 2020 14:03:20 +0200 Subject: [PATCH] Add content element "skillsets" Allow editors to add new content element "skills". The element contains an input for a comma separated list of skill IDs. A preview in backend is shown. Frontend rendering is provided. --- Classes/Backend/Preview.php | 37 ++++++- Classes/Frontend/DataProcessing/SkillSets.php | 63 ++++++++++++ .../Verification/ButtonViewHelper.php | 24 +---- .../Verification/UrlViewHelper.php | 24 +---- .../ViewHelpers/VerificationViewHelper.php | 92 ++++++++++++++++++ .../Mod/Wizards/Skillset.tsconfig | 15 +++ Configuration/Services.yaml | 4 + Configuration/TCA/Overrides/tt_content.php | 10 ++ .../TCA/Overrides/tt_content_skillset.php | 46 +++++++++ Configuration/TypoScript/setup.typoscript | 12 +++ Resources/Private/Language/locallang_be.xlf | 3 + Resources/Private/Language/locallang_tca.xlf | 6 ++ .../Backend/ContentElements/Skillset.html | 18 ++++ .../ContentElements/SkillDisplaySkillSet.html | 13 +++ Resources/Public/Icons/skillset.png | Bin 0 -> 1248 bytes ext_localconf.php | 1 + ext_tables.sql | 1 + 17 files changed, 330 insertions(+), 39 deletions(-) create mode 100644 Classes/Frontend/DataProcessing/SkillSets.php create mode 100644 Classes/ViewHelpers/VerificationViewHelper.php create mode 100644 Configuration/PageTSconfig/Mod/Wizards/Skillset.tsconfig create mode 100644 Configuration/TCA/Overrides/tt_content_skillset.php create mode 100644 Resources/Private/Templates/Backend/ContentElements/Skillset.html create mode 100644 Resources/Private/Templates/ContentElements/SkillDisplaySkillSet.html create mode 100644 Resources/Public/Icons/skillset.png 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 @@ + + + +
    + +
  1. + {skillSet.name}
    +
  2. +
    +
+
+ 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 0000000000000000000000000000000000000000..91aee2c825a886e6dd1fab0665c611aca22f4fb0 GIT binary patch literal 1248 zcmV<61Rwi}P)e@ zV`Fru0X6XjH6o3=ln6$bE)3B>0C1~`km%CjOLS{O0NqzHX?q%_Qse2h;$9hw^P|NBXjN<@4ibkxpq*w4CzQdPOnXwIL?+S9K<~p`n?S=;C=jB&`(eGV;B$Nu&~?~3Oet${EmrT9i&v2=ruZ3v);W(DzyoQIAi{k~%2(vp9>+Dv}>nr$4ss%H#-EJAe{Vg^> zfh{@D=jz8$G-xfBh2@o0{tio-XT}7@PYl|r!0Q>7V!KnZpL5D7{w6#Y`<}#u1^u@P ze|8D|hU3_WZ6ypz*p3(RA!a+YUsUFCN_G9%7HvNs$C7P-6{8&*7>cFLEVeR_ld-_v z($%p?v1%s+*cbnOQP?RaAv0G{Ke0U-N8!UoA#lE>^KZ0=KpBRF5J?{Pn`S0<*I-t%juNy{{A3$9PT+MsF z>VE%*p>e>V4Hz^V-2qp-cqVtB(CK@?^~?%>k)B4U>o&L%9Pp>rS7?`d-9hUs;!3X@ z&rszxSeNXNtEK-oO|5yW|+!m=JDYP6#(LWg7bfpWtQO z-i6^+9dHL;!KcCpk}@{7-ZB+lw+{<9Glzs_UnWg%S;+o+7tiW^+0m^7w%~cZCuq`g z2|E^|?VWC!+9-;@F{{&0%4BdXY1fZooi$)YxY|zQ_)+ zbpNo{3@7O{M`N80`Gbif#)S;9PCuDB;|Bc6OhZFMLqkKu_09h;?`SdU6f}SU0000< KMNUMnLSTZ#>QPw$ literal 0 HcmV?d00001 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, );