mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-30 03:54:10 +01:00
Use the repository manager.
This commit is contained in:
@@ -15,6 +15,7 @@ services:
|
|||||||
- '@netzmacht.contao_leaflet.map.assets'
|
- '@netzmacht.contao_leaflet.map.assets'
|
||||||
- '@netzmacht.contao_leaflet.cache'
|
- '@netzmacht.contao_leaflet.cache'
|
||||||
- '@netzmacht.contao_leaflet.frontend.data_controller'
|
- '@netzmacht.contao_leaflet.frontend.data_controller'
|
||||||
|
- '@netzmacht.contao_toolkit.repository_manager'
|
||||||
|
|
||||||
netzmacht.contao_leaflet.libraries:
|
netzmacht.contao_leaflet.libraries:
|
||||||
class: Netzmacht\Contao\Leaflet\Frontend\Assets\LibrariesConfiguration
|
class: Netzmacht\Contao\Leaflet\Frontend\Assets\LibrariesConfiguration
|
||||||
@@ -86,8 +87,8 @@ services:
|
|||||||
- '@templating'
|
- '@templating'
|
||||||
- '@translator'
|
- '@translator'
|
||||||
- '@netzmacht.contao_leaflet.map.provider'
|
- '@netzmacht.contao_leaflet.map.provider'
|
||||||
|
- '@netzmacht.contao_toolkit.repository_manager'
|
||||||
- '@netzmacht.contao_toolkit.contao.input_adapter'
|
- '@netzmacht.contao_toolkit.contao.input_adapter'
|
||||||
- '@netzmacht.contao_toolkit.contao.config_adapter'
|
|
||||||
tags:
|
tags:
|
||||||
- { name: 'netzmacht.contao_toolkit.component.content_element_factory' }
|
- { name: 'netzmacht.contao_toolkit.component.content_element_factory' }
|
||||||
- { name: 'netzmacht.contao_toolkit.component.content_element', alias: 'leaflet', category: 'includes' }
|
- { name: 'netzmacht.contao_toolkit.component.content_element', alias: 'leaflet', category: 'includes' }
|
||||||
@@ -98,8 +99,8 @@ services:
|
|||||||
- '@templating'
|
- '@templating'
|
||||||
- '@translator'
|
- '@translator'
|
||||||
- '@netzmacht.contao_leaflet.map.provider'
|
- '@netzmacht.contao_leaflet.map.provider'
|
||||||
|
- '@netzmacht.contao_toolkit.repository_manager'
|
||||||
- '@netzmacht.contao_toolkit.contao.input_adapter'
|
- '@netzmacht.contao_toolkit.contao.input_adapter'
|
||||||
- '@netzmacht.contao_toolkit.contao.config_adapter'
|
|
||||||
tags:
|
tags:
|
||||||
- { name: 'netzmacht.contao_toolkit.component.frontend_module_factory' }
|
- { name: 'netzmacht.contao_toolkit.component.frontend_module_factory' }
|
||||||
- { name: 'netzmacht.contao_toolkit.component.frontend_module', alias: 'leaflet', category: 'includes' }
|
- { name: 'netzmacht.contao_toolkit.component.frontend_module', alias: 'leaflet', category: 'includes' }
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Netzmacht\Contao\Leaflet\Frontend;
|
namespace Netzmacht\Contao\Leaflet\Frontend;
|
||||||
|
|
||||||
use Contao\Config;
|
|
||||||
use Contao\Database\Result;
|
use Contao\Database\Result;
|
||||||
use Contao\Input;
|
use Contao\Input;
|
||||||
use Contao\Model;
|
use Contao\Model;
|
||||||
@@ -22,6 +21,7 @@ use Contao\Model\Collection;
|
|||||||
use Netzmacht\Contao\Leaflet\MapProvider;
|
use Netzmacht\Contao\Leaflet\MapProvider;
|
||||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||||
use Netzmacht\Contao\Toolkit\Component\Hybrid\AbstractHybrid;
|
use Netzmacht\Contao\Toolkit\Component\Hybrid\AbstractHybrid;
|
||||||
|
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||||
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
|
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
|
||||||
use Symfony\Component\Translation\TranslatorInterface as Translator;
|
use Symfony\Component\Translation\TranslatorInterface as Translator;
|
||||||
|
|
||||||
@@ -42,42 +42,42 @@ abstract class AbstractMapHybrid extends AbstractHybrid
|
|||||||
/**
|
/**
|
||||||
* The user input.
|
* The user input.
|
||||||
*
|
*
|
||||||
* @var \Input
|
* @var Input
|
||||||
*/
|
*/
|
||||||
private $input;
|
private $input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Contao config.
|
* Repository manager.
|
||||||
*
|
*
|
||||||
* @var \Config
|
* @var RepositoryManager
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $repositoryManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HybridTrait constructor.
|
* HybridTrait constructor.
|
||||||
*
|
*
|
||||||
* @param Result|Model|Collection $model Component model.
|
* @param Result|Model|Collection $model Component model.
|
||||||
* @param TemplateEngine $templateEngine Template engine.
|
* @param TemplateEngine $templateEngine Template engine.
|
||||||
* @param Translator $translator Translator.
|
* @param Translator $translator Translator.
|
||||||
* @param MapProvider $mapProvider Map provider.
|
* @param MapProvider $mapProvider Map provider.
|
||||||
* @param Input $input Request Input.
|
* @param RepositoryManager $repositoryManager Repository manager.
|
||||||
* @param Config $config Config.
|
* @param Input $input Request Input.
|
||||||
* @param string $column Column in which the element appears.
|
* @param string $column Column in which the element appears.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$model,
|
$model,
|
||||||
TemplateEngine $templateEngine,
|
TemplateEngine $templateEngine,
|
||||||
Translator $translator,
|
Translator $translator,
|
||||||
MapProvider $mapProvider,
|
MapProvider $mapProvider,
|
||||||
|
RepositoryManager $repositoryManager,
|
||||||
$input,
|
$input,
|
||||||
$config,
|
|
||||||
$column = null
|
$column = null
|
||||||
) {
|
) {
|
||||||
parent::__construct($model, $templateEngine, $translator, $column);
|
parent::__construct($model, $templateEngine, $translator, $column);
|
||||||
|
|
||||||
$this->mapProvider = $mapProvider;
|
$this->mapProvider = $mapProvider;
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
$this->config = $config;
|
$this->repositoryManager = $repositoryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ use Contao\Input;
|
|||||||
use Netzmacht\Contao\Leaflet\MapProvider;
|
use Netzmacht\Contao\Leaflet\MapProvider;
|
||||||
use Netzmacht\Contao\Toolkit\Component\Component;
|
use Netzmacht\Contao\Toolkit\Component\Component;
|
||||||
use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
|
use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
|
||||||
|
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||||
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
|
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
|
||||||
use Symfony\Component\Translation\TranslatorInterface as Translator;
|
use Symfony\Component\Translation\TranslatorInterface as Translator;
|
||||||
|
|
||||||
@@ -59,33 +60,33 @@ class MapElementFactory implements ComponentFactory
|
|||||||
private $input;
|
private $input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config adapter.
|
* Repository manager.
|
||||||
*
|
*
|
||||||
* @var Config|Adapter
|
* @var RepositoryManager
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $repositoryManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MapElementFactory constructor.
|
* MapElementFactory constructor.
|
||||||
*
|
*
|
||||||
* @param TemplateEngine $engine Template engine.
|
* @param TemplateEngine $engine Template engine.
|
||||||
* @param Translator $translator Translator.
|
* @param Translator $translator Translator.
|
||||||
* @param MapProvider $mapProvider Map provider.
|
* @param MapProvider $mapProvider Map provider.
|
||||||
* @param Input|Adapter $input Input adapter.
|
* @param RepositoryManager $repositoryManager Repository manager.
|
||||||
* @param Config|Adapter $config Config adapter.
|
* @param Input|Adapter $input Input adapter.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
TemplateEngine $engine,
|
TemplateEngine $engine,
|
||||||
Translator $translator,
|
Translator $translator,
|
||||||
MapProvider $mapProvider,
|
MapProvider $mapProvider,
|
||||||
$input,
|
RepositoryManager $repositoryManager,
|
||||||
$config
|
$input
|
||||||
) {
|
) {
|
||||||
$this->templating = $engine;
|
$this->templating = $engine;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->mapProvider = $mapProvider;
|
$this->mapProvider = $mapProvider;
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
$this->config = $config;
|
$this->repositoryManager = $repositoryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,8 +107,8 @@ class MapElementFactory implements ComponentFactory
|
|||||||
$this->templating,
|
$this->templating,
|
||||||
$this->translator,
|
$this->translator,
|
||||||
$this->mapProvider,
|
$this->mapProvider,
|
||||||
|
$this->repositoryManager,
|
||||||
$this->input,
|
$this->input,
|
||||||
$this->config,
|
|
||||||
$column
|
$column
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ use Contao\Input;
|
|||||||
use Netzmacht\Contao\Leaflet\MapProvider;
|
use Netzmacht\Contao\Leaflet\MapProvider;
|
||||||
use Netzmacht\Contao\Toolkit\Component\Component;
|
use Netzmacht\Contao\Toolkit\Component\Component;
|
||||||
use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
|
use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
|
||||||
|
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||||
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
|
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
|
||||||
use Symfony\Component\Translation\TranslatorInterface as Translator;
|
use Symfony\Component\Translation\TranslatorInterface as Translator;
|
||||||
|
|
||||||
@@ -59,33 +60,33 @@ class MapModuleFactory implements ComponentFactory
|
|||||||
private $input;
|
private $input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config adapter.
|
* Repository manager.
|
||||||
*
|
*
|
||||||
* @var Config|Adapter
|
* @var RepositoryManager
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $repositoryManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MapElementFactory constructor.
|
* MapElementFactory constructor.
|
||||||
*
|
*
|
||||||
* @param TemplateEngine $engine Template engine.
|
* @param TemplateEngine $engine Template engine.
|
||||||
* @param Translator $translator Translator.
|
* @param Translator $translator Translator.
|
||||||
* @param MapProvider $mapProvider Map provider.
|
* @param MapProvider $mapProvider Map provider.
|
||||||
* @param Input|Adapter $input Input adapter.
|
* @param RepositoryManager $repositoryManager Repository manager.
|
||||||
* @param Config|Adapter $config Config adapter.
|
* @param Input|Adapter $input Input adapter.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
TemplateEngine $engine,
|
TemplateEngine $engine,
|
||||||
Translator $translator,
|
Translator $translator,
|
||||||
MapProvider $mapProvider,
|
MapProvider $mapProvider,
|
||||||
$input,
|
RepositoryManager $repositoryManager,
|
||||||
$config
|
$input
|
||||||
) {
|
) {
|
||||||
$this->templating = $engine;
|
$this->templating = $engine;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->mapProvider = $mapProvider;
|
$this->mapProvider = $mapProvider;
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
$this->config = $config;
|
$this->repositoryManager = $repositoryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,8 +107,8 @@ class MapModuleFactory implements ComponentFactory
|
|||||||
$this->templating,
|
$this->templating,
|
||||||
$this->translator,
|
$this->translator,
|
||||||
$this->mapProvider,
|
$this->mapProvider,
|
||||||
|
$this->repositoryManager,
|
||||||
$this->input,
|
$this->input,
|
||||||
$this->config,
|
|
||||||
$column
|
$column
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
|||||||
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
||||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||||
|
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||||
use Netzmacht\LeafletPHP\Definition\Map;
|
use Netzmacht\LeafletPHP\Definition\Map;
|
||||||
use Netzmacht\LeafletPHP\Leaflet;
|
use Netzmacht\LeafletPHP\Leaflet;
|
||||||
use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
|
use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
|
||||||
@@ -83,18 +84,24 @@ class MapProvider
|
|||||||
*/
|
*/
|
||||||
private $dataController;
|
private $dataController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository manager.
|
||||||
|
*
|
||||||
|
* @var RepositoryManager
|
||||||
|
*/
|
||||||
|
private $repositoryManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct.
|
* Construct.
|
||||||
*
|
*
|
||||||
* @param DefinitionMapper $mapper The definition mapper.
|
* @param DefinitionMapper $mapper The definition mapper.
|
||||||
* @param Leaflet $leaflet The Leaflet instance.
|
* @param Leaflet $leaflet The Leaflet instance.
|
||||||
* @param EventDispatcher $eventDispatcher The Contao event dispatcher.
|
* @param EventDispatcher $eventDispatcher The Contao event dispatcher.
|
||||||
* @param Input $input Thw request input.
|
* @param Input $input Thw request input.
|
||||||
* @param ContaoAssets $assets Assets handler.
|
* @param ContaoAssets $assets Assets handler.
|
||||||
* @param Cache $cache Cache.
|
* @param Cache $cache Cache.
|
||||||
* @param DataController $dataController Data controller.
|
* @param DataController $dataController Data controller.
|
||||||
*
|
* @param RepositoryManager $repositoryManager Repository manager.
|
||||||
* @internal param FilterFactory $filterFactory Filter factory.
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
DefinitionMapper $mapper,
|
DefinitionMapper $mapper,
|
||||||
@@ -103,15 +110,17 @@ class MapProvider
|
|||||||
$input,
|
$input,
|
||||||
ContaoAssets $assets,
|
ContaoAssets $assets,
|
||||||
Cache $cache,
|
Cache $cache,
|
||||||
DataController $dataController
|
DataController $dataController,
|
||||||
|
RepositoryManager $repositoryManager
|
||||||
) {
|
) {
|
||||||
$this->mapper = $mapper;
|
$this->mapper = $mapper;
|
||||||
$this->leaflet = $leaflet;
|
$this->leaflet = $leaflet;
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
$this->assets = $assets;
|
$this->assets = $assets;
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
$this->dataController = $dataController;
|
$this->dataController = $dataController;
|
||||||
|
$this->repositoryManager = $repositoryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,7 +158,8 @@ class MapProvider
|
|||||||
*/
|
*/
|
||||||
public function getModel($mapId)
|
public function getModel($mapId)
|
||||||
{
|
{
|
||||||
$model = MapModel::findByIdOrAlias($mapId);
|
$repository = $this->repositoryManager->getRepository(MapModel::class);
|
||||||
|
$model = $repository->findByIdOrAlias($mapId);
|
||||||
|
|
||||||
if ($model === null) {
|
if ($model === null) {
|
||||||
throw new \InvalidArgumentException(sprintf('Model "%s" not found', $mapId));
|
throw new \InvalidArgumentException(sprintf('Model "%s" not found', $mapId));
|
||||||
@@ -226,7 +236,8 @@ class MapProvider
|
|||||||
if ($layerId instanceof LayerModel) {
|
if ($layerId instanceof LayerModel) {
|
||||||
$model = $layerId;
|
$model = $layerId;
|
||||||
} else {
|
} else {
|
||||||
$model = LayerModel::findByPK($layerId);
|
$repository = $this->repositoryManager->getRepository(LayerModel::class);
|
||||||
|
$model = $repository->find((int) $layerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$model || !$model->active) {
|
if (!$model || !$model->active) {
|
||||||
|
|||||||
Reference in New Issue
Block a user