You are here

class LayerStyleLoader in farmOS 2.x

Layer style loader.

Hierarchy

Expanded class hierarchy of LayerStyleLoader

1 string reference to 'LayerStyleLoader'
farm_map.services.yml in modules/core/map/farm_map.services.yml
modules/core/map/farm_map.services.yml
1 service uses LayerStyleLoader
farm_map.layer_style_loader in modules/core/map/farm_map.services.yml
Drupal\farm_map\LayerStyleLoader

File

modules/core/map/src/LayerStyleLoader.php, line 11

Namespace

Drupal\farm_map
View source
class LayerStyleLoader implements LayerStyleLoaderInterface {

  /**
   * {@inheritdoc}
   */
  public function load(array $conditions = []) : ?LayerStyleInterface {

    // Load all LayerStyle config entities.

    /** @var \Drupal\farm_map\Entity\LayerStyleInterface[] $layer_styles */
    $layer_styles = LayerStyle::loadMultiple();

    // If there are conditions, filter the styles.
    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 the filtered styles are not empty, return the first one.
    if (!empty($layer_styles)) {
      return reset($layer_styles);
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LayerStyleLoader::load public function Load a single layer style definition, optionally filtered by conditions. Overrides LayerStyleLoaderInterface::load