From a178780c84aa5ece44719e901bb8629eedc87009 Mon Sep 17 00:00:00 2001 From: Alexander Kehr Date: Mon, 14 Oct 2024 11:38:18 +0200 Subject: [PATCH 1/2] contao 5 --- .gitignore | 4 + .php-cs-fixer.dist.php | 28 +++++ .php_cs.dist | 60 ---------- composer.json | 21 +++- config/services.yaml | 9 ++ contao/dca/tl_article.php | 74 ++++++++++++ contao/dca/tl_module.php | 19 +++ .../languages/de/modules.php | 4 +- contao/languages/de/tl_article.php | 24 ++++ .../languages/en/modules.php | 4 +- .../languages/en/tl_article.php | 8 +- contao/templates/.twig-root | 0 .../onepage_navigation.html.twig | 15 +++ .../templates/j_onepage_navigation.html5 | 0 .../templates/js_onepage_navigation.html5 | 2 +- phpstan.neon | 19 +++ .../public => public}/jquery.waypoints.js | 0 .../public => public}/onepage_navigation.js | 0 src/ContaoManager/ContaoManagerPlugin.php | 29 ++--- .../OnepageNavigationController.php | 100 ++++++++++++++++ .../EuFOnepageNavigationExtension.php | 32 +++++ src/EuFOnepageNavigationBundle.php | 9 +- .../GenerateAliasSaveCallback.php | 42 +++++++ src/EventListener/GetArticleListener.php | 37 ++++++ src/EventListener/InsertTagsListener.php | 51 ++++++++ src/Hooks/OnepageHooks.php | 52 -------- src/Modules/ModuleOnepageNavigation.php | 111 ------------------ src/Resources/contao/config/config.php | 25 ---- src/Resources/contao/dca/tl_article.php | 93 --------------- src/Resources/contao/dca/tl_module.php | 17 --- .../contao/languages/de/tl_article.php | 24 ---- .../templates/mod_onepage_navigation.html5 | 17 --- 32 files changed, 500 insertions(+), 430 deletions(-) create mode 100644 .gitignore create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .php_cs.dist create mode 100644 config/services.yaml create mode 100644 contao/dca/tl_article.php create mode 100644 contao/dca/tl_module.php rename {src/Resources/contao => contao}/languages/de/modules.php (73%) create mode 100644 contao/languages/de/tl_article.php rename {src/Resources/contao => contao}/languages/en/modules.php (73%) rename {src/Resources/contao => contao}/languages/en/tl_article.php (50%) create mode 100644 contao/templates/.twig-root create mode 100644 contao/templates/frontend_module/onepage_navigation.html.twig rename {src/Resources/contao => contao}/templates/j_onepage_navigation.html5 (100%) rename {src/Resources/contao => contao}/templates/js_onepage_navigation.html5 (80%) create mode 100644 phpstan.neon rename {src/Resources/public => public}/jquery.waypoints.js (100%) rename {src/Resources/public => public}/onepage_navigation.js (100%) create mode 100644 src/Controller/FrontendModule/OnepageNavigationController.php create mode 100644 src/DependencyInjection/EuFOnepageNavigationExtension.php create mode 100644 src/EventListener/DataContainer/GenerateAliasSaveCallback.php create mode 100644 src/EventListener/GetArticleListener.php create mode 100644 src/EventListener/InsertTagsListener.php delete mode 100644 src/Hooks/OnepageHooks.php delete mode 100644 src/Modules/ModuleOnepageNavigation.php delete mode 100644 src/Resources/contao/config/config.php delete mode 100644 src/Resources/contao/dca/tl_article.php delete mode 100644 src/Resources/contao/dca/tl_module.php delete mode 100644 src/Resources/contao/languages/de/tl_article.php delete mode 100644 src/Resources/contao/templates/mod_onepage_navigation.html5 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..192cd37 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.idea/ +/vendor/ +/composer.lock +/composer.phar \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..f4a4810 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,28 @@ + +@license MIT +@link https://github.com/erdmannfreunde/contao-onepage-navigation +EOF; + +$finder = (new \PhpCsFixer\Finder()) + ->in(__DIR__ . '/src'); + +return (new \PhpCsFixer\Config()) + ->setRules( + [ + '@Symfony' => true, + 'header_comment' => [ + 'header' => $header + ], + ] + ) + ->setFinder($finder) + ->setUsingCache(false) + ->setLineEnding("\r\n"); \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 3fa62bf..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,60 +0,0 @@ - -@license MIT -@link http://github.com/erdmannfreunde/contao-onepage-navigation -EOF; - - -return PhpCsFixer\Config::create() - ->setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - '@PHPUnit60Migration:risky' => true, - 'align_multiline_comment' => true, - 'array_indentation' => true, - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true], - 'braces' => [ - 'allow_single_line_closure' => false, - 'position_after_functions_and_oop_constructs' => 'next', - 'position_after_control_structures' => 'next' - ], - 'combine_consecutive_issets' => true, - 'combine_consecutive_unsets' => true, - 'comment_to_phpdoc' => true, - 'compact_nullable_typehint' => true, - 'declare_strict_types' => true, - 'header_comment' => ['header' => $header], - 'heredoc_to_nowdoc' => true, - 'linebreak_after_opening_tag' => true, - 'native_function_invocation' => [ - 'include' => ['@compiler_optimized'], - ], - 'no_null_property_initialization' => true, - 'no_superfluous_elseif' => true, - 'no_unreachable_default_argument_value' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_strict' => true, - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_order' => true, - 'phpdoc_types_order' => [ - 'null_adjustment' => 'always_last', - 'sort_algorithm' => 'none', - ], - 'strict_comparison' => true, - 'strict_param' => true, - ]) - ->setFinder(PhpCsFixer\Finder::create()->in([__DIR__.'/src'])) - ->setRiskyAllowed(true) - ->setUsingCache(false) -; \ No newline at end of file diff --git a/composer.json b/composer.json index fe19670..a042b09 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,13 @@ }, { "name":"Erdmann & Freunde // Sebastian Buck", - "homepage":"http://erdmann-freunde.de", + "homepage":"https://erdmann-freunde.de", "role":"Developer" + }, + { + "name": "Kehr Solutions", + "homepage": "https://www.kehr-solutions.de", + "role": "Developer" } ], "support":{ @@ -22,10 +27,13 @@ "source":"https://github.com/ErdmannFreunde/contao-onepage-navigation" }, "require":{ - "contao/core-bundle": "~4.9 || ~5.0" + "php": "^8.3", + "contao/core-bundle": "^5.3" }, "require-dev": { - "contao/manager-plugin": "^2.0" + "contao/manager-plugin": "^2.0", + "friendsofphp/php-cs-fixer": "^3.64", + "phpstan/phpstan": "^1.12" }, "replace":{ "sascha-brandhoff/onepage-navigation":"self.version" @@ -37,5 +45,12 @@ }, "extra": { "contao-manager-plugin": "EuF\\OnepageNavigation\\ContaoManager\\ContaoManagerPlugin" + }, + "config": { + "allow-plugins": { + "contao-components/installer": true, + "php-http/discovery": true, + "contao/manager-plugin": true + } } } diff --git a/config/services.yaml b/config/services.yaml new file mode 100644 index 0000000..d43ffce --- /dev/null +++ b/config/services.yaml @@ -0,0 +1,9 @@ +services: + _defaults: + autoconfigure: true + autowire: true + + EuF\OnepageNavigation\EventListener\InsertTagsListener: ~ + EuF\OnepageNavigation\EventListener\GetArticleListener: ~ + EuF\OnepageNavigation\Controller\FrontendModule\OnepageNavigationController: ~ + EuF\OnepageNavigation\EventListener\DataContainer\GenerateAliasSaveCallback: ~ \ No newline at end of file diff --git a/contao/dca/tl_article.php b/contao/dca/tl_article.php new file mode 100644 index 0000000..13a6dd1 --- /dev/null +++ b/contao/dca/tl_article.php @@ -0,0 +1,74 @@ + + * @license MIT + * @link https://github.com/erdmannfreunde/contao-onepage-navigation + */ + +use Contao\CoreBundle\DataContainer\PaletteManipulator; + +/* + * Palettes + */ +PaletteManipulator::create() + ->addLegend('onepage_legend', 'layout_legend', PaletteManipulator::POSITION_BEFORE) + ->addField('addNavigation', 'onepage_legend', PaletteManipulator::POSITION_APPEND) + ->applyToPalette('default', 'tl_article'); + +$GLOBALS['TL_DCA']['tl_article']['palettes']['__selector__'][] = 'addNavigation'; +$GLOBALS['TL_DCA']['tl_article']['subpalettes']['addNavigation'] = 'navigation_title,navigation_jumpTo'; + +/* + * Fields + */ +$GLOBALS['TL_DCA']['tl_article']['fields']['addNavigation'] = [ + 'exclude' => true, + 'inputType' => 'checkbox', + 'eval' => [ + 'submitOnChange' => true, + 'doNotCopy' => true, + ], + 'sql' => [ + 'type' => 'string', + 'length' => 1, + 'fixed' => true, + 'default' => '', + ], +]; + +$GLOBALS['TL_DCA']['tl_article']['fields']['navigation_title'] = [ + 'exclude' => true, + 'inputType' => 'text', + 'search' => true, + 'eval' => [ + 'mandatory' => false, + 'decodeEntities' => true, + 'maxlength' => 255, + 'tl_class' => 'w50', + ], + 'sql' => [ + 'type' => 'string', + 'default' => '', + ], +]; + +$GLOBALS['TL_DCA']['tl_article']['fields']['navigation_jumpTo'] = [ + 'exclude' => true, + 'inputType' => 'text', + 'search' => true, + 'eval' => [ + 'maxlength' => 255, + 'tl_class' => 'w50', + 'rgxp' => 'alias', + ], + 'sql' => [ + 'type' => 'string', + 'default' => '', + ], +]; diff --git a/contao/dca/tl_module.php b/contao/dca/tl_module.php new file mode 100644 index 0000000..c3c963a --- /dev/null +++ b/contao/dca/tl_module.php @@ -0,0 +1,19 @@ + + * @license MIT + * @link https://github.com/erdmannfreunde/contao-onepage-navigation + */ + +use EuF\OnepageNavigation\Controller\FrontendModule\OnepageNavigationController; + +/* + * Palettes + */ +$GLOBALS['TL_DCA']['tl_module']['palettes'][OnepageNavigationController::TYPE] = '{title_legend},name,headline,type;{reference_legend:hide},defineRoot;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;'; diff --git a/src/Resources/contao/languages/de/modules.php b/contao/languages/de/modules.php similarity index 73% rename from src/Resources/contao/languages/de/modules.php rename to contao/languages/de/modules.php index 3c8be8a..9f53693 100644 --- a/src/Resources/contao/languages/de/modules.php +++ b/contao/languages/de/modules.php @@ -5,10 +5,10 @@ /* * Contao Onepage Navigation for Contao Open Source CMS. * - * @copyright Copyright (c) 2021, Erdmann & Freunde + * @copyright Copyright (c) 2024, Erdmann & Freunde * @author Erdmann & Freunde * @license MIT - * @link http://github.com/erdmannfreunde/contao-onepage-navigation + * @link https://github.com/erdmannfreunde/contao-onepage-navigation */ /* diff --git a/contao/languages/de/tl_article.php b/contao/languages/de/tl_article.php new file mode 100644 index 0000000..9fd1359 --- /dev/null +++ b/contao/languages/de/tl_article.php @@ -0,0 +1,24 @@ + + * @license MIT + * @link https://github.com/erdmannfreunde/contao-onepage-navigation + */ + +/* + * Legends + */ +$GLOBALS['TL_LANG']['tl_article']['onepage_legend'] = 'Onepage-Navigation'; + +/* + * Fields + */ +$GLOBALS['TL_LANG']['tl_article']['addNavigation'] = ['Als Navigationspunkt hinzufügen', 'Wenn Sie diesen Artikel zur Navigation hinzufügen möchten, aktivieren Sie bitte die Checkbox.']; +$GLOBALS['TL_LANG']['tl_article']['navigation_title'] = ['Navigationtitel', 'Bitte geben Sie den Titel für die Navigation ein, wenn dieser abweichend vom allgemeinen Titel ist.']; +$GLOBALS['TL_LANG']['tl_article']['navigation_jumpTo'] = ['Sprungmarke', 'Hier können Sie eine optionale Bezeichnung der Sprungmarke eingeben. Diese wird nur gesetzt, wenn Sie keine ID festgelegt haben.']; diff --git a/src/Resources/contao/languages/en/modules.php b/contao/languages/en/modules.php similarity index 73% rename from src/Resources/contao/languages/en/modules.php rename to contao/languages/en/modules.php index 17125bb..18b6708 100644 --- a/src/Resources/contao/languages/en/modules.php +++ b/contao/languages/en/modules.php @@ -5,10 +5,10 @@ /* * Contao Onepage Navigation for Contao Open Source CMS. * - * @copyright Copyright (c) 2021, Erdmann & Freunde + * @copyright Copyright (c) 2024, Erdmann & Freunde * @author Erdmann & Freunde * @license MIT - * @link http://github.com/erdmannfreunde/contao-onepage-navigation + * @link https://github.com/erdmannfreunde/contao-onepage-navigation */ /* diff --git a/src/Resources/contao/languages/en/tl_article.php b/contao/languages/en/tl_article.php similarity index 50% rename from src/Resources/contao/languages/en/tl_article.php rename to contao/languages/en/tl_article.php index 0758979..dbbba97 100644 --- a/src/Resources/contao/languages/en/tl_article.php +++ b/contao/languages/en/tl_article.php @@ -5,10 +5,10 @@ /* * Contao Onepage Navigation for Contao Open Source CMS. * - * @copyright Copyright (c) 2021, Erdmann & Freunde + * @copyright Copyright (c) 2024, Erdmann & Freunde * @author Erdmann & Freunde * @license MIT - * @link http://github.com/erdmannfreunde/contao-onepage-navigation + * @link https://github.com/erdmannfreunde/contao-onepage-navigation */ /* @@ -19,6 +19,6 @@ /* * Fields */ -$GLOBALS['TL_LANG']['tl_article']['addNavigation'] = ['Add as navigation item', 'If you want to add this article to the navigation check this box.']; -$GLOBALS['TL_LANG']['tl_article']['navigation_title'] = ['Alternative title', 'You can define an optional title to be displayed in the navigation for this item.']; +$GLOBALS['TL_LANG']['tl_article']['addNavigation'] = ['Add as navigation item', 'If you want to add this article to the navigation check this box.']; +$GLOBALS['TL_LANG']['tl_article']['navigation_title'] = ['Alternative title', 'You can define an optional title to be displayed in the navigation for this item.']; $GLOBALS['TL_LANG']['tl_article']['navigation_jumpTo'] = ['Anchor', 'Define an optional jump to anchor. It will only be used if you did not define a custom ID.']; diff --git a/contao/templates/.twig-root b/contao/templates/.twig-root new file mode 100644 index 0000000..e69de29 diff --git a/contao/templates/frontend_module/onepage_navigation.html.twig b/contao/templates/frontend_module/onepage_navigation.html.twig new file mode 100644 index 0000000..c8ad34e --- /dev/null +++ b/contao/templates/frontend_module/onepage_navigation.html.twig @@ -0,0 +1,15 @@ +{% extends '@Contao/frontend_module/_base.html.twig' %} + +{% set searchable = false %} + +{% block content %} + {% if hasItems %} + + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/src/Resources/contao/templates/j_onepage_navigation.html5 b/contao/templates/j_onepage_navigation.html5 similarity index 100% rename from src/Resources/contao/templates/j_onepage_navigation.html5 rename to contao/templates/j_onepage_navigation.html5 diff --git a/src/Resources/contao/templates/js_onepage_navigation.html5 b/contao/templates/js_onepage_navigation.html5 similarity index 80% rename from src/Resources/contao/templates/js_onepage_navigation.html5 rename to contao/templates/js_onepage_navigation.html5 index 4eb3df2..0250091 100644 --- a/src/Resources/contao/templates/js_onepage_navigation.html5 +++ b/contao/templates/js_onepage_navigation.html5 @@ -3,7 +3,7 @@