mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-04 22:08:41 +01:00
@@ -35,6 +35,17 @@ class ContaoAssets implements Assets
|
||||
*/
|
||||
private $assetsManager;
|
||||
|
||||
/**
|
||||
* Cached assets.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $cache = [
|
||||
'stylesheets' => [],
|
||||
'javascripts' => [],
|
||||
'map' => []
|
||||
];
|
||||
|
||||
/**
|
||||
* ContaoAssets constructor.
|
||||
*
|
||||
@@ -52,6 +63,8 @@ class ContaoAssets implements Assets
|
||||
*/
|
||||
public function addJavascript($script, $type = self::TYPE_SOURCE)
|
||||
{
|
||||
$this->cache['javascripts'][] = [$script, $type];
|
||||
|
||||
switch ($type) {
|
||||
case static::TYPE_SOURCE:
|
||||
$GLOBALS['TL_HEAD'][] = sprintf('<script>%s</script>', $script);
|
||||
@@ -70,6 +83,8 @@ class ContaoAssets implements Assets
|
||||
*/
|
||||
public function addStylesheet($stylesheet, $type = self::TYPE_FILE)
|
||||
{
|
||||
$this->cache['stylesheets'][] = [$stylesheet, $type];
|
||||
|
||||
switch ($type) {
|
||||
case static::TYPE_SOURCE:
|
||||
$GLOBALS['TL_HEAD'][] = sprintf('<style>%s</style>', $stylesheet);
|
||||
@@ -94,8 +109,39 @@ class ContaoAssets implements Assets
|
||||
*/
|
||||
public function setMap($map)
|
||||
{
|
||||
$this->map = $map;
|
||||
$this->cache['map'] = $map;
|
||||
$this->map = $map;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export to array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* From array.
|
||||
*
|
||||
* @param array $cache Cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fromArray(array $cache)
|
||||
{
|
||||
foreach ($cache['javascripts'] as $javascript) {
|
||||
$this->addJavascript($javascript[0], $javascript[1]);
|
||||
}
|
||||
|
||||
foreach ($cache['stylesheets'] as $stylesheet) {
|
||||
$this->addStylesheet($stylesheet[0], $stylesheet[1]);
|
||||
}
|
||||
|
||||
$this->map = $cache['map'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user