LayerStyleLoader.php in farmOS 2.x
File
modules/core/map/src/LayerStyleLoader.php
View source
<?php
namespace Drupal\farm_map;
use Drupal\farm_map\Entity\LayerStyle;
use Drupal\farm_map\Entity\LayerStyleInterface;
class LayerStyleLoader implements LayerStyleLoaderInterface {
public function load(array $conditions = []) : ?LayerStyleInterface {
$layer_styles = LayerStyle::loadMultiple();
if (!empty($conditions)) {
foreach ($conditions as $key => $value) {
$layer_styles = array_filter($layer_styles, function ($layer_style) use ($key, $value) {
$style_conditions = $layer_style
->getConditions();
if (isset($style_conditions[$key])) {
if (is_array($style_conditions[$key]) && in_array($value, $style_conditions[$key])) {
return TRUE;
}
if ($style_conditions[$key] == $value) {
return TRUE;
}
}
return FALSE;
});
}
}
if (!empty($layer_styles)) {
return reset($layer_styles);
}
return NULL;
}
}