diff --git a/CHANGELOG.md b/CHANGELOG.md index 91ace23..99b1fc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Deprecate `Netzmacht\Contao\Leaflet\Frontend\RequestUrl`. Use router to generate request url for layer data. - Deprecate `Netzmacht\Contao\Leaflet\Frontend\DataController`. Use introduced endpoint to get map data. + +### Changed + + - Rewritten about page using own route (#48). ### Fixed diff --git a/src/Backend/About.php b/src/Backend/Action/AboutAction.php similarity index 65% rename from src/Backend/About.php rename to src/Backend/Action/AboutAction.php index 5678f3a..8e0e178 100644 --- a/src/Backend/About.php +++ b/src/Backend/Action/AboutAction.php @@ -10,32 +10,59 @@ * @filesource */ -namespace Netzmacht\Contao\Leaflet\Backend; +namespace Netzmacht\Contao\Leaflet\Backend\Action; -use Contao\BackendTemplate; +use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as Engine; +use Symfony\Component\HttpFoundation\Response; /** * Credits backend module. * * @package Netzmacht\Contao\Leaflet\Backend */ -class About +final class AboutAction { + /** + * Templating engine. + * + * @var Engine + */ + private $engine; + + /** + * Project directory. + * + * @var string + */ + private $projectDir; + + /** + * AboutAction constructor. + * + * @param Engine $engine Templating engine. + * @param string $projectDir Project directory. + */ + public function __construct(Engine $engine, string $projectDir) + { + $this->engine = $engine; + $this->projectDir = $projectDir; + } + /** * Generate the backend view. * * @return string */ - public function generate() + public function __invoke(): Response { - $template = new BackendTemplate('be_leaflet_about'); + $data = [ + 'headline' => 'Leaftlet maps integration for Contao CMS', + 'libraries' => $this->getLibraries(), + ]; - $template->headline = 'Leaftlet maps integration for Contao CMS'; - $template->libraries = $this->getLibraries(); + [$data['version'], $data['dependencies']] = $this->extractFromComposer(); - list($template->version, $template->dependencies) = $this->extractFromComposer(); - - return $template->parse(); + return $this->engine->renderResponse('@NetzmachtContaoLeaflet/backend/about.html.twig', $data); } /** @@ -45,7 +72,7 @@ class About * * @SuppressWarnings(PHPMD.Superglobals) */ - private function getLibraries() + private function getLibraries(): array { return array_map( function ($library) { @@ -70,7 +97,7 @@ class About array_filter( $GLOBALS['LEAFLET_LIBRARIES'], function ($library) { - return isset($library['name']) && isset($library['license']); + return isset($library['name'], $library['license']); } ) ); @@ -81,10 +108,10 @@ class About * * @return array */ - private function extractFromComposer() + private function extractFromComposer(): array { - $extFile = TL_ROOT . '/vendor/netzmacht/contao-leaflet-maps/composer.json'; - $lockFile = TL_ROOT . '/composer.lock'; + $extFile = $this->projectDir . '/vendor/netzmacht/contao-leaflet-maps/composer.json'; + $lockFile = $this->projectDir . '/composer.lock'; if (!file_exists($extFile) || !file_exists($lockFile)) { return []; diff --git a/src/Bundle/ContaoManager/Plugin.php b/src/Bundle/ContaoManager/Plugin.php index f9f6d52..b5420a1 100644 --- a/src/Bundle/ContaoManager/Plugin.php +++ b/src/Bundle/ContaoManager/Plugin.php @@ -61,11 +61,6 @@ class Plugin implements BundlePluginInterface, RoutingPluginInterface return null; } - $collection = $loader->load(__DIR__ . '/../Resources/config/routing.yml'); - if ($collection instanceof RouteCollection) { - $collection->addPrefix('leaflet/api'); - } - - return $collection; + return $loader->load(__DIR__ . '/../Resources/config/routing.yml'); } } diff --git a/src/Bundle/Resources/config/listeners.yml b/src/Bundle/Resources/config/listeners.yml index 16622f6..afd2b09 100644 --- a/src/Bundle/Resources/config/listeners.yml +++ b/src/Bundle/Resources/config/listeners.yml @@ -113,3 +113,13 @@ services: - '@netzmacht.contao_leaflet.definition.builder' tags: - { name: 'contao.hook', hook: 'initializeSystem', method: 'onInitializeSystem' } + + netzmacht.contao_leaflet.listeners.backend_menu: + class: Netzmacht\Contao\Leaflet\Listener\Backend\UserNavigationListener + arguments: + - '@request_stack' + - '@router' + - '@translator' + - '@netzmacht.contao_toolkit.assets_manager' + tags: + - { name: 'contao.hook', hook: 'getUserNavigation', method: '__invoke'} diff --git a/src/Bundle/Resources/config/routing.yml b/src/Bundle/Resources/config/routing.yml index 371ec1a..b210bcc 100644 --- a/src/Bundle/Resources/config/routing.yml +++ b/src/Bundle/Resources/config/routing.yml @@ -1,5 +1,5 @@ leaflet_layer: - path: /layer/{layerId} + path: /leaflet/api/layer/{layerId} controller: Netzmacht\Contao\Leaflet\Frontend\Action\LayerDataAction defaults: _leaflet_scope: page @@ -9,3 +9,10 @@ leaflet_layer: _format: geojson context: \w+ contextId: \d+ + +leaflet_backend_about: + path: /contao/leaflet/about + controller: Netzmacht\Contao\Leaflet\Backend\Action\AboutAction + defaults: + _scope: backend + _backend_module: leaflet_about diff --git a/src/Bundle/Resources/config/services.yml b/src/Bundle/Resources/config/services.yml index 454f01c..e7cff08 100644 --- a/src/Bundle/Resources/config/services.yml +++ b/src/Bundle/Resources/config/services.yml @@ -131,3 +131,8 @@ services: arguments: - '@netzmacht.contao_leaflet.map.provider' - '@netzmacht.contao_leaflet.filter_factory' + + Netzmacht\Contao\Leaflet\Backend\Action\AboutAction: + arguments: + - '@templating' + - '%kernel.project_dir%' diff --git a/src/Bundle/Resources/contao/config/config.php b/src/Bundle/Resources/contao/config/config.php index 29595b8..9f4431c 100644 --- a/src/Bundle/Resources/contao/config/config.php +++ b/src/Bundle/Resources/contao/config/config.php @@ -40,11 +40,6 @@ array_insert( 'stylesheet' => 'bundles/netzmachtcontaoleaflet/css/backend.css', 'javascript' => 'bundles/netzmachtcontaoleaflet/js/backend.js', ], - 'leaflet_about' => [ - 'callback' => Netzmacht\Contao\Leaflet\Backend\About::class, - 'icon' => 'bundles/netzmachtcontaoleaflet/img/about.png', - 'stylesheet' => 'bundles/netzmachtcontaoleaflet/css/about.css', - ], ], ] ); diff --git a/src/Bundle/Resources/contao/templates/be_leaflet_about.html5 b/src/Bundle/Resources/contao/templates/be_leaflet_about.html5 deleted file mode 100644 index 15835f2..0000000 --- a/src/Bundle/Resources/contao/templates/be_leaflet_about.html5 +++ /dev/null @@ -1,140 +0,0 @@ -
-
-

headline; ?> - version; ?> -

-
- -
-

About

-
-

- The Leaflet maps integration for Contao CMS is an Open Source Software license under the LGPL 3.0. - This extension is only exists because of great other Open Source Software which it heavenly depends on. -

-

- This software ships with an visible attribution to netzmacht creative in the map attribution - control. - If you want to remove this attribution, you have to purchase a commercial license. - For more details visit the project - website. -

-
-
- - -

- netzmacht
- David Molineus
-

-

- DAB Bank München
- IBAN: DE52701204008354237003
- BIC: DABBDEMMXXX -

-
- - - - -
-
-
- -
-

Support Contao Leaflet

- -
-
-

Report issues

-

If you found a bug, got some troubles or have a feature request - feel free to open an issue.

-

Issue - tracker

-
-
-

Contribute

-

There are many ways you can con­tribute. Translations, - docu­mentation or code contributions are welcome. -

-

Contribute -

-
-
-

Fund a feature

-

Contao Leaflet is not feature complete. Have a look at the list of planned feature and support - them.

-

Planned - features

-
-
-
- -
-

Individual development

-

If you have special requirements you can hire me for an individual development.

-

Contact

-
-
-

Commercial license

-

If you want to remove the attribution in the attribution control, you can purchase a commercial - license.

-

Purchase - license

-
-
-
- -
-

Credits

- - - - - - - - libraries): ?> - - - - - libraries as $library): ?> - - - - - - - - - - - - - - - - - - - - - - - dependencies): ?> - - - - - dependencies as $dep): ?> - - - - - - - -
NameVersionLicenseHomepage
Libraries
Graphics
Farm Fresh-Web Icons3.9.2CC BY 3.0 USfatcow.com/free-icons
Web Blog Icons by SEM Labs3.9.2CC BY 4.0semlabs.co.uk
Dependencies
-
-
diff --git a/src/Bundle/Resources/views/backend/about.html.twig b/src/Bundle/Resources/views/backend/about.html.twig new file mode 100644 index 0000000..33f07ba --- /dev/null +++ b/src/Bundle/Resources/views/backend/about.html.twig @@ -0,0 +1,124 @@ +{% extends "@ContaoCore/Backend/be_page.html.twig" %} + +{% block headline %}{{ "MOD.leaflet_about.1"|trans({}, 'contao_modules') }}{% endblock %} + +{% block main %} +
+
+

{{ headline }} + {{ version }} +

+
+ +
+

About

+

+ The Leaflet maps integration for Contao CMS is an Open Source Software license under the LGPL 3.0. + This extension is only exists because of great other Open Source Software which it heavenly depends on. +

+

+ This software ships with an visible attribution to netzmacht creative in the map attribution + control. + If you want to remove this attribution, you have to purchase a commercial license. + For more details visit the project + website. +

+
+ +
+

Support Contao Leaflet

+ +
+
+

Report issues

+

If you found a bug, got some troubles or have a feature request - feel free to open an issue.

+

Issue + tracker

+
+
+

Contribute

+

There are many ways you can con­tribute. Translations, + docu­mentation or code contributions are welcome. +

+

Contribute +

+
+
+

Fund a feature

+

Contao Leaflet is not feature complete. Have a look at the list of planned feature and support + them.

+

Planned + features

+
+
+
+ +
+

Individual development

+

If you have special requirements you can hire me for an individual development.

+

Contact

+
+
+

Commercial license

+

If you want to remove the attribution in the attribution control, you can purchase a commercial + license.

+

Purchase + license

+
+
+
+ +
+

Credits

+ + + + + + + + {% if libraries %} + + + + {% endif %} + {% for library in libraries %} + + + + + + + {% endfor %} + + + + + + + + + + + + + + + + {% if dependencies %} + + + + {% endif %} + {% for dep in dependencies %} + + + + + + + {% endfor %} +
NameVersionLicenseHomepage
Libraries
{{ library.name }}{{ library.version }}{{ library.license|raw }}{{ library.homepage|raw }}
Graphics
Farm Fresh-Web Icons3.9.2CC BY 3.0 USfatcow.com/free-icons
Web Blog Icons by SEM Labs3.9.2CC BY 4.0semlabs.co.uk
Dependencies
{{ dep.name }}{{ dep.version }}{{ dep.license|raw }}{{ dep.homepage|raw }}
+
+
+{% endblock %} diff --git a/src/Listener/Backend/UserNavigationListener.php b/src/Listener/Backend/UserNavigationListener.php new file mode 100644 index 0000000..b42789e --- /dev/null +++ b/src/Listener/Backend/UserNavigationListener.php @@ -0,0 +1,107 @@ + + * @copyright 2014-2018 netzmacht David Molineus. All rights reserved. + * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE + * @filesource + */ + +declare(strict_types=1); + +namespace Netzmacht\Contao\Leaflet\Listener\Backend; + +use Contao\CoreBundle\Event\MenuEvent; +use Netzmacht\Contao\Toolkit\View\Assets\AssetsManager; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\Routing\RouterInterface as Router; +use Symfony\Component\Translation\TranslatorInterface as Translator; + +/** + * Class BackendMenuListener adds backend entries to the navigation. + */ +final class UserNavigationListener +{ + /** + * Request stack. + * + * @var RequestStack + */ + private $requestStack; + + /** + * Router. + * + * @var Router + */ + private $router; + + /** + * Translator. + * + * @var Translator + */ + private $translator; + + /** + * Assets manager. + * + * @var AssetsManager + */ + private $assets; + + /** + * BackendUserNavigationListener constructor. + * + * @param RequestStack $requestStack Request stack. + * @param Router $router Router. + * @param Translator $translator Translator. + * @param AssetsManager $assets Assets manager. + */ + public function __construct( + RequestStack $requestStack, + Router $router, + Translator $translator, + AssetsManager $assets + ) { + $this->requestStack = $requestStack; + $this->router = $router; + $this->translator = $translator; + $this->assets = $assets; + } + + /** + * Handle the event. + * + * @param array $modules Backend navigation modules. + * + * @return array + */ + public function __invoke(array $modules): array + { + if (!isset($modules['leaflet'])) { + return $modules; + } + + $request = $this->requestStack->getCurrentRequest(); + $isActive = $request && $request->attributes->get('_backend_module') === 'leaflet_about'; + + $modules['leaflet']['modules']['leaflet_about'] = [ + 'label' => $this->translator->trans('MOD.leaflet_about.0', [], 'contao_modules'), + 'title' => $this->translator->trans('MOD.leaflet_about.1', [], 'contao_modules'), + 'href' => $this->router->generate('leaflet_backend_about'), + 'icon' => 'bundles/netzmachtcontaoleaflet/img/about.png', + 'class' => 'navigation leaflet_about', + 'isActive' => $isActive, + ]; + + if ($isActive) { + $this->assets->addStylesheet('bundles/netzmachtcontaoleaflet/css/about.css'); + } + + return $modules; + } +}