You are here

public function IpGeoLocGlobal::markerColors in IP Geolocation Views & Maps 8

Return available marker colors for use in a select drop-down. List is compiled based on available .png files in ip_geoloc/markers dir.

Return value

array Array of color names indexed by machine names

File

src/Services/IpGeoLocGlobal.php, line 355

Class

IpGeoLocGlobal
Class IpGeoLocGlobal.

Namespace

Drupal\ip_geoloc\Services

Code

public function markerColors() {
  $color_list =& drupal_static(__FUNCTION__);
  if (!isset($color_list)) {
    $color_list = [
      '' => '<' . t('default') . '>',
      0 => '<' . t('no marker') . '>',
    ];
    if ($directory_handle = opendir($this
      ->markerDirectory())) {
      while (($filename = readdir($directory_handle)) !== FALSE) {
        if ($ext_pos = strrpos($filename, '.png')) {
          $color = Unicode::substr($filename, 0, $ext_pos);

          // Ok... relies on translations done elsewhere.
          // @TODO dependency injection
          // $color_list[$color] = t($color);
          $color_list[$color] = $color;
        }
      }
      closedir($directory_handle);
    }
    asort($color_list);
  }
  return $color_list;
}