Skip to content

Commit

Permalink
[BUGFIX] Conditionally add dashboard widget
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NarkNiro committed Sep 25, 2024
1 parent a861672 commit ad77bdf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
35 changes: 21 additions & 14 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
])
;
}
};
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit ad77bdf

Please sign in to comment.