From 7bbc5b9a0275a484b9510f0e193a0393ebcdc442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6rner?= Date: Tue, 21 Feb 2023 14:50:14 +0100 Subject: [PATCH] load asset in addToTemplate method, fixed warnings --- CHANGELOG.md | 4 +++ composer.json | 3 +- src/ContaoManager/Plugin.php | 2 +- src/Resources/contao/config/config.php | 23 ++----------- src/Widget/ListWidget.php | 46 ++++++++++++++++++++------ 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c92d33..b2635a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [1.2.0] - 2022-03-04 +- Changed: load assets only on pages where widget is used +- Fixed: deprecation warning + ## [1.1.0] - 2022-03-04 - Changed: allow php 8 - Changed: allow symfony/kernel 5 diff --git a/composer.json b/composer.json index 1320685..3e2b783 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,9 @@ "ext-json": "*", "contao/core-bundle": "^4.4", "symfony/http-kernel": "^3.4 || ^4.0 || ^5.0", - "heimrichhannot/contao-request-bundle": "^1.1.1", "heimrichhannot/contao-ajax-bundle": "~1.0", + "heimrichhannot/contao-request-bundle": "^1.1.1", + "heimrichhannot/contao-utils-bundle": "^2.225", "heimrichhannot/datatables": "^1.10", "heimrichhannot/datatables-additional": "^1.0" }, diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 81acfc7..232d030 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -21,7 +21,7 @@ class Plugin implements BundlePluginInterface { - public function getBundles(ParserInterface $parser) + public function getBundles(ParserInterface $parser): array { return [ BundleConfig::create(HeimrichHannotListWidgetBundle::class)->setLoadAfter([ diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php index 772deed..dca985c 100644 --- a/src/Resources/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -1,25 +1,8 @@ class = $arrConfig['class']; - $objTemplate->ajax = $arrConfig['ajax']; - $objTemplate->headerFields = $arrConfig['headerFields']; - $objTemplate->columnDefs = htmlentities(json_encode(static::getColumnDefsData($arrConfig['columns']))); - $objTemplate->language = htmlentities(json_encode($arrConfig['language'])); - - if ($arrConfig['ajax']) { - $objTemplate->processingAction = System::getContainer()->get('huh.utils.url')->addQueryString( - 'key=' . static::LOAD_ACTION . '&scope=' . $arrConfig['identifier'] . '&rt=' . RequestToken::get() + $configuration = array_merge([ + 'loadAssets' => true, + ], $configuration); + + $objTemplate->class = $configuration['class']; + $objTemplate->ajax = $configuration['ajax']; + $objTemplate->headerFields = $configuration['headerFields']; + $objTemplate->columnDefs = htmlentities(json_encode(static::getColumnDefsData($configuration['columns']))); + $objTemplate->language = htmlentities(json_encode($configuration['language'])); + + if ($configuration['ajax']) { + $objTemplate->processingAction = System::getContainer()->get(Utils::class)->url()->addQueryStringParameterToUrl( + 'key=' . static::LOAD_ACTION . '&scope=' . $configuration['identifier'] . '&rt=' . RequestToken::get() ); } else { - $objTemplate->items = $arrConfig['items']; + $objTemplate->items = $configuration['items']; + } + + if ($configuration['loadAssets']) { + $GLOBALS['TL_JAVASCRIPT']['datatables-i18n'] = 'assets/datatables-additional/datatables-i18n/datatables-i18n.min.js'; + $GLOBALS['TL_JAVASCRIPT']['datatables-core'] = 'assets/datatables/datatables/media/js/jquery.dataTables.min.js'; + $GLOBALS['TL_JAVASCRIPT']['datatables-rowReorder'] = 'assets/datatables-additional/datatables-RowReorder/js/dataTables.rowReorder.min.js'; + + $GLOBALS['TL_JAVASCRIPT']['jquery.list_widget.js'] = 'bundles/heimrichhannotlistwidget/assets/js/jquery.list_widget.js'; + + $GLOBALS['TL_CSS']['datatables-core'] = 'assets/datatables-additional/datatables.net-dt/css/jquery.dataTables.min.css'; + $GLOBALS['TL_CSS']['datatables-rowReorder'] = 'assets/datatables-additional/datatables-RowReorder/css/rowReorder.dataTables.min.css'; } }