You are here

public function MarkerIconService::getLegendIconFromFid in Geofield Map 8.2

Generate Legend Icon from Uploaded File.

Parameters

int $fid: The file identifier. The file identifier.

string $image_style: The image style identifier.

Return value

array The icon view render array..

File

src/Services/MarkerIconService.php, line 502

Class

MarkerIconService
Provides an Icon Managed File Service.

Namespace

Drupal\geofield_map\Services

Code

public function getLegendIconFromFid($fid, $image_style = 'none') {
  $icon_element = [];
  try {

    /* @var \Drupal\file\Entity\file $file */
    $file = $this->entityManager
      ->getStorage('file')
      ->load($fid);
    if ($file instanceof FileInterface) {
      $this->defaultIconElement['#uri'] = $file
        ->getFileUri();
      switch ($image_style) {
        case 'none':
          $icon_element = [
            '#weight' => -10,
            '#theme' => 'image',
            '#uri' => $file
              ->getFileUri(),
          ];
          break;
        default:
          $icon_element = [
            '#weight' => -10,
            '#theme' => 'image_style',
            '#uri' => $file
              ->getFileUri(),
            '#style_name' => '',
          ];
          if ($this->moduleHandler
            ->moduleExists('image') && ImageStyle::load($image_style) && !$this
            ->fileIsManageableSvg($file)) {
            $icon_element['#style_name'] = $image_style;
          }
          else {
            $icon_element = $this->defaultIconElement;
          }
      }
    }
  } catch (\Exception $e) {
    watchdog_exception('geofield_map', $e);
  }
  return $icon_element;
}