From 60306459d291f28b11bbcabaf7fdde6c2996e6e0 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Tue, 17 Oct 2017 18:18:33 +0200 Subject: [PATCH] Add the file path to the layer label. --- .../Label/Layer/FileLabelRenderer.php | 48 +++++++++++++++++++ src/Bundle/Resources/config/layers.yml | 5 ++ 2 files changed, 53 insertions(+) create mode 100644 src/Backend/Renderer/Label/Layer/FileLabelRenderer.php diff --git a/src/Backend/Renderer/Label/Layer/FileLabelRenderer.php b/src/Backend/Renderer/Label/Layer/FileLabelRenderer.php new file mode 100644 index 0000000..6c2256a --- /dev/null +++ b/src/Backend/Renderer/Label/Layer/FileLabelRenderer.php @@ -0,0 +1,48 @@ + + * @copyright 2014-2017 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\Backend\Renderer\Label\Layer; + +use Contao\FilesModel; +use Symfony\Component\Translation\TranslatorInterface as Translator; + +/** + * Class FileLabelRenderer + * + * @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer + */ +class FileLabelRenderer extends AbstractLabelRenderer +{ + /** + * {@inheritDoc} + */ + protected function getLayerType(): string + { + return 'file'; + } + + /** + * {@inheritDoc} + */ + public function render(array $row, string $label, Translator $translator): string + { + $file = FilesModel::findByPk($row['file']); + + if ($file) { + $label .= ' (' . $file->path . ')'; + } + + return $label; + } +} diff --git a/src/Bundle/Resources/config/layers.yml b/src/Bundle/Resources/config/layers.yml index 6a36bf1..ce7f93f 100644 --- a/src/Bundle/Resources/config/layers.yml +++ b/src/Bundle/Resources/config/layers.yml @@ -84,3 +84,8 @@ services: class: Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\VectorsLabelRenderer tags: - { name: 'netzmacht.contao_leaflet.layer_label_renderer' } + + netzmacht.contao_leaflet.layer_label_renderer.file: + class: Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\FileLabelRenderer + tags: + - { name: 'netzmacht.contao_leaflet.layer_label_renderer' }