You are here

protected function ImagemagickFormatMapper::resolveEnabledFormats in ImageMagick 8

Same name and namespace in other branches
  1. 8.3 src/ImagemagickFormatMapper.php \Drupal\imagemagick\ImagemagickFormatMapper::resolveEnabledFormats()
  2. 8.2 src/ImagemagickFormatMapper.php \Drupal\imagemagick\ImagemagickFormatMapper::resolveEnabledFormats()

Returns the enabled image formats, processing the config map.

Results are cached for subsequent access. Saving the config will invalidate the cache.

Return value

array An associative array with ImageMagick formats as keys and their MIME type as values.

2 calls to ImagemagickFormatMapper::resolveEnabledFormats()
ImagemagickFormatMapper::getEnabledFormats in src/ImagemagickFormatMapper.php
Gets the list of currently enabled image formats.
ImagemagickFormatMapper::resolveEnabledExtensions in src/ImagemagickFormatMapper.php
Returns the enabled image file extensions, processing the config map.

File

src/ImagemagickFormatMapper.php, line 171

Class

ImagemagickFormatMapper
Provides the ImageMagick format mapper.

Namespace

Drupal\imagemagick

Code

protected function resolveEnabledFormats() {
  if ($cache = $this->cache
    ->get("imagemagick:enabled_formats")) {
    $enabled_image_formats = $cache->data;
  }
  else {
    $config = $this->configFactory
      ->get('imagemagick.settings');
    $image_formats = $config
      ->get('image_formats');
    $enabled_image_formats = [];
    foreach ($image_formats as $format => $data) {
      if (!isset($data['enabled']) || isset($data['enabled']) && $data['enabled']) {
        if (isset($data['mime_type']) && in_array($data['mime_type'], $this->mimeTypeMapper
          ->getMimeTypes())) {
          $enabled_image_formats[$format] = $data['mime_type'];
        }
      }
    }
    ksort($enabled_image_formats);
    $this->cache
      ->set("imagemagick:enabled_formats", $enabled_image_formats, Cache::PERMANENT, $config
      ->getCacheTags());
  }
  return $enabled_image_formats;
}