Skip to content

Commit

Permalink
[TASK] Provide compatibility with TYPO3 v13.0 (#13)
Browse files Browse the repository at this point in the history
This includes some cleanup tasks.
  • Loading branch information
sebkln committed Feb 12, 2024
1 parent cbdaea0 commit 4cefbd9
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Classes/Controllers/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Classes/Domain/Repository/FileReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -55,7 +54,7 @@ function (FileReference $reference) {
)
);

$rowCount = $query->execute()->rowCount();
$rowCount = $query->executeQuery()->rowCount();
return $rowCount > 0;
}
);
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Repository/PictureTermsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
37 changes: 22 additions & 15 deletions Classes/Form/Element/TermsInputElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, array<int, string|JavaScriptModuleInstruction>|string> As defined in initializeResultArray() of AbstractNode
*/
public function render(): array
{
$row = $this->data['databaseRow'];
$parameterArray = $this->data['parameterArray'];
Expand All @@ -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 = [
Expand All @@ -85,6 +89,7 @@ public function render():array
$iconColor = $colors['notMandatory'];

$fieldId = StringUtility::getUniqueId('formengine-input-');
$renderedLabel = $this->renderLabel($fieldId);

$attributes = [
'id' => $fieldId,
Expand Down Expand Up @@ -133,6 +138,8 @@ public function render():array
return $resultArray = [];
}

$html = [];
$html[] = $renderedLabel;
$html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
$html[] = $fieldInformationHtml;
$html[] = '<div class="form-control-wrap">';
Expand Down
38 changes: 20 additions & 18 deletions Classes/Form/Element/TermsRadioElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -155,7 +157,7 @@ public function render()
$html[] = '</div>';
$html[] = '</div>';

$resultArray['html'] = implode(LF, $html);
$resultArray['html'] = $this->wrapWithFieldsetAndLegend(implode(LF, $html));
return $resultArray;
}
}
30 changes: 24 additions & 6 deletions Classes/Utility/TableConfigurationUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
],
],
];
Expand All @@ -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
],
],
],
];
Expand Down
4 changes: 4 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion Configuration/TCA/Overrides/sys_file_metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions Configuration/TCA/picture_terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'label' => 'name',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'rootLevel' => 1,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
Expand All @@ -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' => [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions Resources/Private/Layouts/Backend/Default.html

This file was deleted.

2 changes: 1 addition & 1 deletion Resources/Private/Templates/Backend/Import.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
data-namespace-typo3-fluid="true">

<f:layout name="Default"/>
<f:layout name="Module"/>

<f:section name="Content">
<h1>
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
1 change: 0 additions & 1 deletion ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4cefbd9

Please sign in to comment.