Skip to content

Commit

Permalink
[BUGFIX] Avoid error in site configuration with TYPO3 v12.3
Browse files Browse the repository at this point in the history
This patch also avoids triggering a deprecation notice about TCA migrations in the upcoming v12.4.

Resolves: #44
  • Loading branch information
brotkrueml committed Apr 1, 2023
1 parent 376e042 commit 27fb620
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Error when opening a site configuration in TYPO3 v12.3 (#44)

## [2.1.0] - 2023-01-07

### Added
Expand Down
14 changes: 11 additions & 3 deletions Classes/Configuration/WidgetsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Brotkrueml\MatomoWidgets\Configuration;

use Brotkrueml\MatomoWidgets\Extension;
use TYPO3\CMS\Core\Information\Typo3Version;

/**
* @internal
Expand Down Expand Up @@ -52,15 +53,22 @@ public function getWidgetIdentifiers(): array
}

/**
* @return array<array{string, string}>
* @return array<non-empty-array<0|1|'label'|'value', string>>
*/
public function getItemsForTca(): array
{
$labelKey = 'label';
$valueKey = 'value';
if ((new Typo3Version())->getMajorVersion() < 12) {
$labelKey = 0;
$valueKey = 1;
}

$items = [];
foreach ($this->availableWidgets as $identifier => $languageKey) {
$items[] = [
$languageKey,
$identifier,
$labelKey => $languageKey,
$valueKey => $identifier,
];
}

Expand Down
17 changes: 13 additions & 4 deletions Configuration/SiteConfiguration/Overrides/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
'type' => 'check',
'renderType' => 'checkboxToggle',
'items' => [[
0 => '',
1 => '',
'label' => '',
'value' => '',
]],
],
'onChange' => 'reload',
Expand All @@ -75,6 +75,15 @@
$GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsUrl']['displayCond'] = 'FIELD:matomoWidgetsConsiderMatomoIntegration:REQ:false';
$GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsIdSite']['displayCond'] = 'FIELD:matomoWidgetsConsiderMatomoIntegration:REQ:false';
$GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsPagesNotFoundTemplate']['displayCond'] = 'FIELD:matomoWidgetsConsiderMatomoIntegration:REQ:false';

if ((new TYPO3\CMS\Core\Information\Typo3Version())->getMajorVersion() < 12) {
$GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsConsiderMatomoIntegration']['config']['items'][0][0]
= $GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsConsiderMatomoIntegration']['config']['items'][0]['label'];
$GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsConsiderMatomoIntegration']['config']['items'][0][1]
= $GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsConsiderMatomoIntegration']['config']['items'][0]['value'];
unset($GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsConsiderMatomoIntegration']['config']['items'][0]['label']);
unset($GLOBALS['SiteConfiguration']['site']['columns']['matomoWidgetsConsiderMatomoIntegration']['config']['items'][0]['value']);
}
}

$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] .= ',
Expand All @@ -90,8 +99,8 @@
'showitem' =>
(
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('matomo_integration')
? 'matomoWidgetsConsiderMatomoIntegration, --linebreak--, '
: ''
? 'matomoWidgetsConsiderMatomoIntegration, --linebreak--, '
: ''
) . 'matomoWidgetsUrl, matomoWidgetsIdSite, matomoWidgetsTokenAuth',
],
'matomoWidgetsActiveWidgets' => [
Expand Down
6 changes: 6 additions & 0 deletions Documentation/Changelog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
`Unreleased <https://github.com/brotkrueml/typo3-matomo-widgets/compare/v2.1.0...HEAD>`_
--------------------------------------------------------------------------------------------

Fixed
^^^^^


* Error when opening a site configuration in TYPO3 v12.3 (#44)

`2.1.0 <https://github.com/brotkrueml/typo3-matomo-widgets/compare/v2.0.0...v2.1.0>`_ - 2023-01-07
------------------------------------------------------------------------------------------------------

Expand Down
88 changes: 87 additions & 1 deletion Tests/Unit/Configuration/WidgetsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Brotkrueml\MatomoWidgets\Configuration\WidgetsProvider;
use Brotkrueml\MatomoWidgets\Extension;
use PHPUnit\Framework\TestCase;
use TYPO3\CMS\Core\Information\Typo3Version;

class WidgetsProviderTest extends TestCase
{
Expand Down Expand Up @@ -54,8 +55,12 @@ public function getWidgetIdentifiers(): void
/**
* @test
*/
public function getItemsForTca(): void
public function getItemsForTcaInV11(): void
{
if ((new Typo3Version())->getMajorVersion() > 11) {
self::markTestSkipped('Only relevant for TYPO3 v11');
}

$actual = $this->subject->getItemsForTca();

self::assertContains([Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.visitsSummary.actionsPerDay.title', 'actionsPerDay'], $actual);
Expand All @@ -76,4 +81,85 @@ public function getItemsForTca(): void
self::assertContains([Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.visitsSummary.visitsPerDay.title', 'visitsPerDay'], $actual);
self::assertContains([Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.visitsSummary.visitsPerMonth.title', 'visitsPerMonth'], $actual);
}

/**
* @test
*/
public function getItemsForTca(): void
{
if ((new Typo3Version())->getMajorVersion() < 12) {
self::markTestSkipped('Only relevant for TYPO3 v12+');
}

$actual = $this->subject->getItemsForTca();

self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.visitsSummary.actionsPerDay.title',
'value' => 'actionsPerDay',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.visitsSummary.actionsPerMonth.title',
'value' => 'actionsPerMonth',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.annotations.title',
'value' => 'annotations',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.createAnnotation.title',
'value' => 'createAnnotation',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.visitsSummary.bounceRate.title',
'value' => 'bounceRate',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.referrers.campaigns.title',
'value' => 'campaigns',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.contents.contentNames.title',
'value' => 'contentNames',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.contents.contentPieces.title',
'value' => 'contentPieces',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.userCountry.country.title',
'value' => 'countries',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.events.javaScriptErrors.title',
'value' => 'javaScriptErrors',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.linkMatomo.title',
'value' => 'linkMatomo',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.devicesDetection.osFamilies.title',
'value' => 'osFamilies',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.actions.pagesNotFound.title',
'value' => 'pagesNotFound',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.actions.siteSearchKeywords.title',
'value' => 'siteSearchKeywords',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.actions.siteSearchNoResultKeywords.title',
'value' => 'siteSearchNoResultKeywords',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.visitsSummary.visitsPerDay.title',
'value' => 'visitsPerDay',
], $actual);
self::assertContains([
'label' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.visitsSummary.visitsPerMonth.title',
'value' => 'visitsPerMonth',
], $actual);
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"require": {
"php": ">=8.1",
"symfony/finder": "^5.4 || ^6.2",
"typo3/cms-core": "^11.5 || ^12.1",
"typo3/cms-dashboard": "^11.5 || ^12.1"
"typo3/cms-core": "^11.5 || ^12.3",
"typo3/cms-dashboard": "^11.5 || ^12.3"
},
"require-dev": {
"brotkrueml/coding-standards": "~4.0.0",
Expand Down

0 comments on commit 27fb620

Please sign in to comment.