mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-30 20:13:49 +01:00
76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Leaflet maps for Contao CMS.
|
|
*
|
|
* @package contao-leaflet-maps
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
|
* @copyright 2014-2017 netzmacht David Molineus. All rights reserved.
|
|
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
|
|
* @filesource
|
|
*/
|
|
|
|
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
|
|
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
|
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
|
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
|
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
|
use Netzmacht\LeafletPHP\Definition;
|
|
|
|
/**
|
|
* Class ReferenceLayerMapper maps an reference layer to another layer.
|
|
*
|
|
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
|
*/
|
|
class ReferenceLayerMapper extends AbstractLayerMapper
|
|
{
|
|
/**
|
|
* Layer type.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected static $type = 'reference';
|
|
|
|
/**
|
|
* Repository manager.
|
|
*
|
|
* @var RepositoryManager
|
|
*/
|
|
private $repositoryManager;
|
|
|
|
/**
|
|
* Construct.
|
|
*
|
|
* @param RepositoryManager $repositoryManager Repository manager.
|
|
*/
|
|
public function __construct(RepositoryManager $repositoryManager)
|
|
{
|
|
$this->repositoryManager = $repositoryManager;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function handle(
|
|
$model,
|
|
DefinitionMapper $mapper,
|
|
Request $request = null,
|
|
$elementId = null,
|
|
Definition $parent = null
|
|
) {
|
|
$repository = $this->repositoryManager->getRepository(LayerModel::class);
|
|
$reference = $repository->findByPk($model->reference);
|
|
|
|
if (!$reference || !$reference->active) {
|
|
return null;
|
|
}
|
|
|
|
$elementId = $model->standalone ? $this->getElementId($model, $elementId) : null;
|
|
|
|
return $mapper->handle($reference, $request, $elementId);
|
|
}
|
|
}
|