You are here

function _responsive_image_image_style_url in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/responsive_image/responsive_image.module \_responsive_image_image_style_url()

Wrapper around image_style_url() so we can return an empty image.

2 calls to _responsive_image_image_style_url()
template_preprocess_responsive_image in core/modules/responsive_image/responsive_image.module
Prepares variables for a responsive image.
_responsive_image_build_source_attributes in core/modules/responsive_image/responsive_image.module
Helper function for template_preprocess_responsive_image().

File

core/modules/responsive_image/responsive_image.module, line 492
Responsive image display formatter for image fields.

Code

function _responsive_image_image_style_url($style_name, $path) {
  if ($style_name == ResponsiveImageStyleInterface::EMPTY_IMAGE) {

    // The smallest data URI for a 1px square transparent GIF image.
    // http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
    return 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
  }

  /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
  $file_url_generator = \Drupal::service('file_url_generator');
  $entity = ImageStyle::load($style_name);
  if ($entity instanceof ImageStyle) {
    return $file_url_generator
      ->transformRelative($entity
      ->buildUrl($path));
  }
  return $file_url_generator
    ->generateString($path);
}