function ResponsiveImageStyle::addImageStyleMapping

Same name in other branches
  1. 9 core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php \Drupal\responsive_image\Entity\ResponsiveImageStyle::addImageStyleMapping()
  2. 8.9.x core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php \Drupal\responsive_image\Entity\ResponsiveImageStyle::addImageStyleMapping()
  3. 10 core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php \Drupal\responsive_image\Entity\ResponsiveImageStyle::addImageStyleMapping()

Overrides ResponsiveImageStyleInterface::addImageStyleMapping

File

core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php, line 116

Class

ResponsiveImageStyle
Defines the responsive image style entity.

Namespace

Drupal\responsive_image\Entity

Code

public function addImageStyleMapping($breakpoint_id, $multiplier, array $image_style_mapping) {
    // If there is an existing mapping, overwrite it.
    foreach ($this->image_style_mappings as &$mapping) {
        if ($mapping['breakpoint_id'] === $breakpoint_id && $mapping['multiplier'] === $multiplier) {
            $mapping = $image_style_mapping + [
                'breakpoint_id' => $breakpoint_id,
                'multiplier' => $multiplier,
            ];
            $this->sortMappings();
            return $this;
        }
    }
    $this->image_style_mappings[] = $image_style_mapping + [
        'breakpoint_id' => $breakpoint_id,
        'multiplier' => $multiplier,
    ];
    $this->sortMappings();
    return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.