diff --git a/CHANGELOG.md b/CHANGELOG.md index 99b1fc6..2d561a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Custom route to load map data. - Add distance filter support for the marker layer (Bounds Mode "fit" has to be enabled). - Add support for relative css units for map size definition (#59). + - Add hint that zoom level is probably required (#56). ### Deprecated @@ -23,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed + - Require PHP 7.1. - Rewritten about page using own route (#48). ### Fixed diff --git a/src/Bundle/Resources/config/listeners.yml b/src/Bundle/Resources/config/listeners.yml index afd2b09..692bc00 100644 --- a/src/Bundle/Resources/config/listeners.yml +++ b/src/Bundle/Resources/config/listeners.yml @@ -30,6 +30,8 @@ services: - '@netzmacht.contao_toolkit.dca.manager' - '@database_connection' - '@netzmacht.contao_toolkit.repository_manager' + - '@translator' + - '@session' netzmacht.contao_leaflet.listeners.dca.control: class: Netzmacht\Contao\Leaflet\Listener\Dca\ControlDcaListener diff --git a/src/Bundle/Resources/contao/dca/tl_leaflet_map.php b/src/Bundle/Resources/contao/dca/tl_leaflet_map.php index 6b701f2..c293b32 100644 --- a/src/Bundle/Resources/contao/dca/tl_leaflet_map.php +++ b/src/Bundle/Resources/contao/dca/tl_leaflet_map.php @@ -23,6 +23,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = [ ], 'onload_callback' => [ ['netzmacht.contao_leaflet.listeners.dca.leaflet', 'loadLanguageFile'], + ['netzmacht.contao_leaflet.listeners.dca.map', 'addIncompleteConfigurationWarning'], ], 'onsubmit_callback' => [ ['netzmacht.contao_leaflet.listeners.dca.leaflet', 'clearCache'], diff --git a/src/Bundle/Resources/contao/languages/en/default.php b/src/Bundle/Resources/contao/languages/en/default.php new file mode 100644 index 0000000..fc4b709 --- /dev/null +++ b/src/Bundle/Resources/contao/languages/en/default.php @@ -0,0 +1,15 @@ + + * @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); + +$GLOBALS['TL_LANG']['ERR']['leafletMissingZoomLevel'] = 'No zoom level defined. Only leave it empty on purpose (Zoom level might by initialized by bounds adjustments). Otherwise no map will be shown.'; diff --git a/src/Listener/Dca/MapDcaListener.php b/src/Listener/Dca/MapDcaListener.php index 2a4077e..fa74ef4 100644 --- a/src/Listener/Dca/MapDcaListener.php +++ b/src/Listener/Dca/MapDcaListener.php @@ -15,14 +15,20 @@ declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\Listener\Dca; use Contao\DataContainer; +use Contao\Input; use Contao\StringUtil; use Doctrine\DBAL\Connection; use Netzmacht\Contao\Leaflet\Model\LayerModel; +use Netzmacht\Contao\Leaflet\Model\MapModel; use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager; use Netzmacht\Contao\Toolkit\Dca\Listener\AbstractListener; use Netzmacht\Contao\Toolkit\Dca\Manager; use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder; use PDO; +use function strlen; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Translation\TranslatorInterface as Translator; +use function var_dump; /** * Class Map is the helper class for the tl_leaflet_map dca. @@ -52,19 +58,70 @@ class MapDcaListener extends AbstractListener */ private $repositoryManager; + /** + * Translator. + * + * @var Translator + */ + private $translator; + + /** + * Session. + * + * @var Session + */ + private $session; + /** * Construct. * * @param Manager $manager Data container manager. * @param Connection $connection Database connection. * @param RepositoryManager $repositoryManager Repository manager. + * @param Translator $translator Translator. + * @param Session $session Session. */ - public function __construct(Manager $manager, Connection $connection, RepositoryManager $repositoryManager) - { + public function __construct( + Manager $manager, + Connection $connection, + RepositoryManager $repositoryManager, + Translator $translator, + Session $session + ) { parent::__construct($manager); $this->connection = $connection; $this->repositoryManager = $repositoryManager; + $this->translator = $translator; + $this->session = $session; + } + + /** + * Add warnings for incomplete configurations. + * + * @param DataContainer $dataContainer The data container driver. + * + * @return void + */ + public function addIncompleteConfigurationWarning($dataContainer): void + { + if (Input::get('act') !== 'edit') { + return; + } + + $repository = $this->repositoryManager->getRepository(MapModel::class); + $map = $repository->find((int) $dataContainer->id); + + if (!$map) { + return; + } + + if ($map->zoom === null || $map->zoom === '') { + $this->session->getFlashBag()->add( + 'contao.BE.info', + $this->translator->trans('ERR.leafletMissingZoomLevel', [], 'contao_default') + ); + } } /**