From cc8e4bb6c4801912f26d70da9c626a0b307ea7a7 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 16 Sep 2024 09:33:10 +0200 Subject: [PATCH] [BUGFIX] Conditionally add dashboard widget Ensure the DeepL translate usage widget is registered only if the 'dashboard' extension is loaded. This prevents errors in environments where the 'dashboard' extension is not available by execute the cache flush action. --- Configuration/Services.php | 35 +++++++++++++++++++++-------------- composer.json | 3 ++- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Configuration/Services.php b/Configuration/Services.php index 44fd09ba..81fe737d 100644 --- a/Configuration/Services.php +++ b/Configuration/Services.php @@ -10,6 +10,7 @@ use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\DependencyInjection\SingletonPass; use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Dashboard\WidgetRegistry; use WebVision\WvDeepltranslate\Client; use WebVision\WvDeepltranslate\ClientInterface; use WebVision\WvDeepltranslate\Command\GlossaryCleanupCommand; @@ -158,18 +159,24 @@ ] ); - $services->set('widgets.deepltranslate.widget.useswidget') - ->class(UsageWidget::class) - ->arg('$view', new Reference('dashboard.views.widget')) - ->arg('$options', []) - ->tag('dashboard.widget', [ - 'identifier' => 'widgets-deepl-uses', - 'groupNames' => 'deepl', - 'title' => 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.title', - 'description' => 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.description', - 'iconIdentifier' => 'content-widget-list', - 'height' => 'medium', - 'width' => 'small', - ]) - ; + /** + * Check if WidgetRegistry is defined, which means that EXT:dashboard is available. + * Registration directly in Services.yaml will break without EXT:dashboard installed! + */ + if ($containerBuilder->hasDefinition(WidgetRegistry::class)) { + $services->set('widgets.deepltranslate.widget.useswidget') + ->class(UsageWidget::class) + ->arg('$view', new Reference('dashboard.views.widget')) + ->arg('$options', []) + ->tag('dashboard.widget', [ + 'identifier' => 'widgets-deepl-uses', + 'groupNames' => 'deepl', + 'title' => 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.title', + 'description' => 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.description', + 'iconIdentifier' => 'content-widget-list', + 'height' => 'medium', + 'width' => 'small', + ]) + ; + } }; diff --git a/composer.json b/composer.json index d83eed00..453db732 100644 --- a/composer.json +++ b/composer.json @@ -107,7 +107,8 @@ "suggest": { "b13/container": "Just to be loaded after EXT:container", "web-vision/enable-translated-content": "Adds enable translated content button to language columns in page view", - "web-vision/deepltranslate-assets": "Enables the translation of files in FileList Modal via deepl" + "web-vision/deepltranslate-assets": "Enables the translation of files in FileList Modal via deepl", + "typo3/cms-dashboard": "Install the package to enable the widgets from deepltranslate packages" }, "autoload": { "psr-4": {