LeafletTileLayerPluginManager.php in Geofield Map 8.2
File
src/LeafletTileLayerPluginManager.php
View source
<?php
namespace Drupal\geofield_map;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class LeafletTileLayerPluginManager extends DefaultPluginManager {
protected $requestStack;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, RequestStack $request_stack) {
parent::__construct('Plugin/LeafletTileLayerPlugin', $namespaces, $module_handler, 'Drupal\\geofield_map\\LeafletTileLayerPluginInterface', 'Drupal\\geofield_map\\Annotation\\LeafletTileLayerPlugin');
$this
->alterInfo('geofield_map_leaflet_tile_layer_plugin_info');
$this
->setCacheBackend($cache_backend, 'geofield_map_leaflet_tile_layer_plugin_plugins');
$this->requestStack = $request_stack;
}
public function getLeafletTileLayers() {
$leaflet_tile_layers = [];
foreach ($this
->getDefinitions() as $k => $plugin) {
$plugin['url'] = $this->requestStack
->getCurrentRequest()
->isSecure() ? preg_replace("/^http:/i", "https:", $plugin['url']) : $plugin['url'];
$leaflet_tile_layers[$k] = [
'label' => $plugin['label'],
'url' => $plugin['url'],
'options' => $plugin['options'],
];
}
ksort($leaflet_tile_layers);
return $leaflet_tile_layers;
}
public function getLeafletTilesLayersOptions() {
$options = [];
foreach ($this
->getDefinitions() as $k => $plugin) {
$options[$k] = $plugin['label'];
}
ksort($options);
return $options;
}
}