You are here

private static function ResponsiveBackgroundImage::createSingleMediaQuery in Responsive Background Image 8

Parameters

string $media_query: CSS media query from Breakpoint group config.

string $css_selector: CSS selector for element that will have background image.

string $image_path: Path to image.

string $multiplier: Responsive image multiplier/pixel ratio.

Return value

string A single CSS media query for one one window width and one multiplier/pixel ratio.

1 call to ResponsiveBackgroundImage::createSingleMediaQuery()
ResponsiveBackgroundImage::generateMediaQueries in src/ResponsiveBackgroundImage.php
Generates a Drupal style tag array containing CSS media queries to apply a responsive background image to a specific DOM element/node. The return value must be assigned correctly. See the return description below.

File

src/ResponsiveBackgroundImage.php, line 203

Class

ResponsiveBackgroundImage
Provides a method to generate a responsive background image using a Responsive Image Style.

Namespace

Drupal\responsive_background_image

Code

private static function createSingleMediaQuery(string $media_query, string $css_selector, string $image_path, string $multiplier) {
  switch ($multiplier) {
    case '1x':
      $min_pixel_ratio = '';
      break;
    default:
      $min_pixel_ratio = 'and (min-device-pixel-ratio: 1.5)';
      break;
  }
  return '
    @media ' . $media_query . $min_pixel_ratio . ' {
      ' . $css_selector . ' {
        background-image: url(' . $image_path . ');
      }
    }';
}