From 4cefbd9751155c73aafc27e90a6bab01b6adb9cc Mon Sep 17 00:00:00 2001 From: Sebastian Klein Date: Mon, 12 Feb 2024 14:44:06 +0100 Subject: [PATCH] [TASK] Provide compatibility with TYPO3 v13.0 (#13) This includes some cleanup tasks. --- Classes/Controllers/BackendController.php | 4 +- .../Repository/FileReferenceRepository.php | 3 +- .../Repository/PictureTermsRepository.php | 4 +- Classes/Form/Element/TermsInputElement.php | 37 ++++++++++-------- Classes/Form/Element/TermsRadioElement.php | 38 ++++++++++--------- Classes/Utility/TableConfigurationUtility.php | 30 ++++++++++++--- Configuration/Services.yaml | 4 ++ .../TCA/Overrides/sys_file_metadata.php | 4 +- Configuration/TCA/picture_terms.php | 5 +-- README.md | 2 +- .../Private/Layouts/Backend/Default.html | 6 --- .../Private/Templates/Backend/Import.html | 2 +- composer.json | 4 +- ext_emconf.php | 2 +- ext_tables.sql | 1 - 15 files changed, 85 insertions(+), 61 deletions(-) delete mode 100644 Resources/Private/Layouts/Backend/Default.html diff --git a/Classes/Controllers/BackendController.php b/Classes/Controllers/BackendController.php index 2ab570e..628fb59 100644 --- a/Classes/Controllers/BackendController.php +++ b/Classes/Controllers/BackendController.php @@ -62,8 +62,8 @@ public function __construct( public function importAction(): ResponseInterface { $moduleTemplate = $this->moduleTemplateFactory->create($this->request); - $moduleTemplate->setContent($this->view->render()); - return $this->htmlResponse($moduleTemplate->renderContent()); + $moduleTemplate->setFlashMessageQueue($this->getFlashMessageQueue()); + return $moduleTemplate->renderResponse('Import'); } public function importDefaultRecordsAction(): ResponseInterface diff --git a/Classes/Domain/Repository/FileReferenceRepository.php b/Classes/Domain/Repository/FileReferenceRepository.php index b3e4ab3..f8d3d4c 100644 --- a/Classes/Domain/Repository/FileReferenceRepository.php +++ b/Classes/Domain/Repository/FileReferenceRepository.php @@ -27,7 +27,6 @@ public function initializeObject(): void /** @var QuerySettingsInterface $defaultQuerySettings */ $defaultQuerySettings = GeneralUtility::makeInstance(QuerySettingsInterface::class); $defaultQuerySettings->setRespectStoragePage(false); - $defaultQuerySettings->setLanguageOverlayMode(false); $this->setDefaultQuerySettings($defaultQuerySettings); } @@ -55,7 +54,7 @@ function (FileReference $reference) { ) ); - $rowCount = $query->execute()->rowCount(); + $rowCount = $query->executeQuery()->rowCount(); return $rowCount > 0; } ); diff --git a/Classes/Domain/Repository/PictureTermsRepository.php b/Classes/Domain/Repository/PictureTermsRepository.php index 94a38ac..c57e036 100644 --- a/Classes/Domain/Repository/PictureTermsRepository.php +++ b/Classes/Domain/Repository/PictureTermsRepository.php @@ -47,9 +47,9 @@ public function findByTermsUid(int $uid): array ->select('*') ->from('picture_terms') ->where( - $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \TYPO3\CMS\Core\Database\Connection::PARAM_INT)) ) - ->execute() + ->executeQuery() ->fetchAssociative(); if (!is_array($row)) { diff --git a/Classes/Form/Element/TermsInputElement.php b/Classes/Form/Element/TermsInputElement.php index deeb78c..54ae663 100644 --- a/Classes/Form/Element/TermsInputElement.php +++ b/Classes/Form/Element/TermsInputElement.php @@ -34,29 +34,29 @@ class TermsInputElement extends AbstractFormElement ], ]; - /** - * @var IconFactory - */ - protected $iconFactory; - /** * @var PictureTermsRepository */ protected $pictureTermsRepository; - /** - * @param NodeFactory $nodeFactory - * @param array $data - */ - public function __construct(NodeFactory $nodeFactory, array $data) - { - parent::__construct($nodeFactory, $data); - - $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); + public function __construct( + NodeFactory $nodeFactory, + IconFactory $iconFactory + ) { + $this->nodeFactory = $nodeFactory; + $this->iconFactory = $iconFactory; $this->pictureTermsRepository = GeneralUtility::makeInstance(PictureTermsRepository::class); } - public function render():array + public function setData(array $data): void + { + $this->data = $data; + } + + /** + * @return array|string> As defined in initializeResultArray() of AbstractNode + */ + public function render(): array { $row = $this->data['databaseRow']; $parameterArray = $this->data['parameterArray']; @@ -69,6 +69,10 @@ public function render():array $fieldInformationResult = $this->renderFieldInformation(); $fieldInformationHtml = $fieldInformationResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($this->initializeResultArray(), $fieldInformationResult, false); + + // Needed to keep TYPO3 v12 compatibility: + $resultArray['labelHasBeenHandled'] = true; + $itemValue = $parameterArray['itemFormElValue']; $icons = [ @@ -85,6 +89,7 @@ public function render():array $iconColor = $colors['notMandatory']; $fieldId = StringUtility::getUniqueId('formengine-input-'); + $renderedLabel = $this->renderLabel($fieldId); $attributes = [ 'id' => $fieldId, @@ -133,6 +138,8 @@ public function render():array return $resultArray = []; } + $html = []; + $html[] = $renderedLabel; $html[] = '
'; $html[] = $fieldInformationHtml; $html[] = '
'; diff --git a/Classes/Form/Element/TermsRadioElement.php b/Classes/Form/Element/TermsRadioElement.php index db46bd6..31e0d69 100644 --- a/Classes/Form/Element/TermsRadioElement.php +++ b/Classes/Form/Element/TermsRadioElement.php @@ -9,6 +9,7 @@ use TYPO3\CMS\Backend\Form\Element\AbstractFormElement; use TYPO3\CMS\Backend\Form\NodeFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\StringUtility; /** * Class TermsRadioElement @@ -36,23 +37,24 @@ class TermsRadioElement extends AbstractFormElement */ protected $pictureTermsRepository; - /** - * @param NodeFactory $nodeFactory - * @param array $data - */ - public function __construct(NodeFactory $nodeFactory, array $data) - { - parent::__construct($nodeFactory, $data); + public function __construct( + NodeFactory $nodeFactory + ) { + $this->nodeFactory = $nodeFactory; $this->pictureTermsRepository = GeneralUtility::makeInstance(PictureTermsRepository::class); } + public function setData(array $data): void + { + $this->data = $data; + } /** * This will render a series of radio buttons. * * @return array As defined in initializeResultArray() of AbstractNode */ - public function render() + public function render(): array { $row = $this->data['databaseRow']; $resultArray = $this->initializeResultArray(); @@ -105,23 +107,23 @@ public function render() $items = [ 0 => [ - 0 => $this->getLanguageService()->sL($labelDefault) . ' (' . $this->getLanguageService()->sL($labelDefaultValue) . ')', - 1 => 0, + 'label' => $this->getLanguageService()->sL($labelDefault) . ' (' . $this->getLanguageService()->sL($labelDefaultValue) . ')', + 'value' => 0, ], 1 => [ - 0 => $this->getLanguageService()->sL($labelYes), - 1 => 1, + 'label' => $this->getLanguageService()->sL($labelYes), + 'value' => 1, ], 2 => [ - 0 => $this->getLanguageService()->sL($labelNo), - 1 => 2, + 'label' => $this->getLanguageService()->sL($labelNo), + 'value' => 2, ], ]; foreach ($items as $itemNumber => $itemLabelAndValue) { - $label = $itemLabelAndValue[0]; - $value = $itemLabelAndValue[1]; - $radioId = htmlspecialchars($this->data['parameterArray']['itemFormElID'] . '_' . $itemNumber); + $label = $itemLabelAndValue['label']; + $value = $itemLabelAndValue['value']; + $radioId = htmlspecialchars(StringUtility::getUniqueId('formengine-radio-') . '-' . $itemNumber); $radioElementAttrs = array_merge( [ 'type' => 'radio', @@ -155,7 +157,7 @@ public function render() $html[] = '
'; $html[] = '
'; - $resultArray['html'] = implode(LF, $html); + $resultArray['html'] = $this->wrapWithFieldsetAndLegend(implode(LF, $html)); return $resultArray; } } diff --git a/Classes/Utility/TableConfigurationUtility.php b/Classes/Utility/TableConfigurationUtility.php index cccbdbc..83f2558 100644 --- a/Classes/Utility/TableConfigurationUtility.php +++ b/Classes/Utility/TableConfigurationUtility.php @@ -28,10 +28,22 @@ public static function getFullMetadataFieldTCAConfig($fieldName, array $configur 'type' => 'select', 'renderType' => 'selectSingle', 'items' => [ - [$ll . 'type.metadata_field_type.hidden', MetadataFieldType::HIDDEN], - [$ll . 'type.metadata_field_type.optional', MetadataFieldType::OPTIONAL], - [$ll . 'type.metadata_field_type.mandatory', MetadataFieldType::MANDATORY], - [$ll . 'type.metadata_field_type.mandatory_if_present', MetadataFieldType::MANDATORY_IF_PRESENT], + [ + 'label' => $ll . 'type.metadata_field_type.hidden', + 'value' => MetadataFieldType::HIDDEN + ], + [ + 'label' => $ll . 'type.metadata_field_type.optional', + 'value' => MetadataFieldType::OPTIONAL + ], + [ + 'label' => $ll . 'type.metadata_field_type.mandatory', + 'value' => MetadataFieldType::MANDATORY + ], + [ + 'label' => $ll . 'type.metadata_field_type.mandatory_if_present', + 'value' => MetadataFieldType::MANDATORY_IF_PRESENT + ], ], ], ]; @@ -58,8 +70,14 @@ public static function getOptionalMetadataFieldTCAConfig($fieldName, array $conf 'type' => 'select', 'renderType' => 'selectSingle', 'items' => [ - [$ll . 'type.metadata_field_type.hidden', MetadataFieldType::HIDDEN], - [$ll . 'type.metadata_field_type.optional', MetadataFieldType::OPTIONAL], + [ + 'label' => $ll . 'type.metadata_field_type.hidden', + 'value' => MetadataFieldType::HIDDEN + ], + [ + 'label' => $ll . 'type.metadata_field_type.optional', + 'value' => MetadataFieldType::OPTIONAL + ], ], ], ]; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 5c8ab96..123cd8b 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -9,3 +9,7 @@ services: exclude: - '../Classes/Domain/Model/' - '../Classes/Domain/Types/' + Mfc\Picturecredits\Form\Element\TermsInputElement: + public: true + Mfc\Picturecredits\Form\Element\TermsRadioElement: + public: true diff --git a/Configuration/TCA/Overrides/sys_file_metadata.php b/Configuration/TCA/Overrides/sys_file_metadata.php index 50e83b3..698ba85 100644 --- a/Configuration/TCA/Overrides/sys_file_metadata.php +++ b/Configuration/TCA/Overrides/sys_file_metadata.php @@ -18,10 +18,12 @@ 'config' => [ 'type' => 'select', 'renderType' => 'selectSingle', + 'items' => [ + ['label' => '', 'value' => 0], + ], 'foreign_table' => 'picture_terms', 'foreign_table_where' => 'AND {#picture_terms}.{#pid} = 0 AND {#picture_terms}.{#l10n_parent} = 0', 'default' => 0, - 'items' => [['', 0]] ], 'onChange' => 'reload', 'l10n_mode' => 'exclude', diff --git a/Configuration/TCA/picture_terms.php b/Configuration/TCA/picture_terms.php index 59001db..31fd8b6 100644 --- a/Configuration/TCA/picture_terms.php +++ b/Configuration/TCA/picture_terms.php @@ -16,7 +16,6 @@ 'label' => 'name', 'tstamp' => 'tstamp', 'crdate' => 'crdate', - 'cruser_id' => 'cruser_id', 'rootLevel' => 1, 'languageField' => 'sys_language_uid', 'transOrigPointerField' => 'l10n_parent', @@ -42,13 +41,13 @@ 'config' => [ 'type' => 'select', 'renderType' => 'selectSingle', - 'default' => 0, 'items' => [ - ['', 0], + ['label' => '', 'value' => 0], ], 'foreign_table' => $table, 'foreign_table_where' => 'AND ' . $table . '.pid=###CURRENT_PID### AND ' . $table . '.sys_language_uid IN (-1,0)', + 'default' => 0, ], ], 'l10n_diffsource' => [ diff --git a/README.md b/README.md index 6ab6fea..90efbd6 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ secure to avoid written warnings. ## Compatibility -TYPO3 12.4.9 - 12.4.99 +TYPO3 12.4.9 - 13.0.99 ## Installation diff --git a/Resources/Private/Layouts/Backend/Default.html b/Resources/Private/Layouts/Backend/Default.html deleted file mode 100644 index 3f5f217..0000000 --- a/Resources/Private/Layouts/Backend/Default.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Resources/Private/Templates/Backend/Import.html b/Resources/Private/Templates/Backend/Import.html index c0556e6..99c35e6 100644 --- a/Resources/Private/Templates/Backend/Import.html +++ b/Resources/Private/Templates/Backend/Import.html @@ -3,7 +3,7 @@ xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers" data-namespace-typo3-fluid="true"> - +

diff --git a/composer.json b/composer.json index 3575b4c..a0b4da5 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ ], "require": { "php": ">=8.1", - "typo3/cms-core": ">=12.4.9 <12.4.99", - "typo3/cms-frontend": ">=12.4.9 <12.4.99" + "typo3/cms-core": ">=12.4.9 <13.0.99", + "typo3/cms-frontend": ">=12.4.9 <13.0.99" }, "extra": { "typo3/cms": { diff --git a/ext_emconf.php b/ext_emconf.php index e024d7f..7066b0e 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -11,7 +11,7 @@ 'version' => '2.0.2', 'constraints' => [ 'depends' => [ - 'typo3' => '12.4.9-12.4.99', + 'typo3' => '12.4.9-13.0.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/ext_tables.sql b/ext_tables.sql index d0ecd64..dc96bde 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -7,7 +7,6 @@ CREATE TABLE `picture_terms` ( tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, - cruser_id int(11) unsigned DEFAULT '0' NOT NULL, deleted smallint unsigned DEFAULT '0' NOT NULL, hidden smallint unsigned DEFAULT '0' NOT NULL, starttime int(11) unsigned DEFAULT '0' NOT NULL,