You are here

public function VisibilityChecker::isValidImageStyle in Image Lazyloader 8

Asserts if a uri is a valid image style.

Parameters

string $uri: The uri.

Return value

bool Whether or not this is a valid image style.

File

src/VisibilityChecker.php, line 104

Class

VisibilityChecker
Class VisibilityChecker.

Namespace

Drupal\lazyloader

Code

public function isValidImageStyle($uri) {
  $excluded_styles = $this
    ->filterSelectedValues($this->configFactory
    ->get('lazyloader.exclude')
    ->get('image_styles'));

  // If no image styles are selected we have nothing to exclude.
  if (empty($excluded_styles)) {
    return TRUE;
  }
  $styles = implode('|', array_keys($this->imageStyleStorage
    ->loadMultiple()));

  // Make sure the image is actually a derived image.
  if (!preg_match('/styles\\/[' . $styles . ']/', $uri)) {

    // Not a derived image, nothing to do here.
    return TRUE;
  }
  $excluded_styles = implode('|', $excluded_styles);
  return !preg_match('/styles\\/[' . $excluded_styles . ']/', $uri);
}