diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index de47e1f..4b7cb0d 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -226,6 +226,32 @@ function template_preprocess_responsive_image(&$variables) { /** * Helper function for template_preprocess_responsive_image(). * + * @param \Drupal\Core\Image\ImageInterface $image + * The image to build the tags for. + * @param array $variables + * An array with the following keys: + * - responsive_image_style_id: The \Drupal\responsive_image\Entity\ResponsiveImageStyle + * ID. + * - width: The width of the image (if known). + * - height: The height of the image (if known). + * - uri: The URI of the image file. + * @param \Drupal\breakpoint\BreakpointInterface $breakpoint + * The breakpoint for this source tag. + * @param array $multipliers + * An array with multipliers as keys and image style mappings as values. + * + * @return \Drupal\Core\Template\Attribute[] + * An array of attributes for the source tag. + * + * @deprecated in Drupal 8.3.x and will be removed before 9.0.0. + */ +function responsive_image_build_source_attributes(ImageInterface $image, array $variables, BreakpointInterface $breakpoint, array $multipliers) { + return _responsive_image_build_source_attributes($variables, $breakpoint, $multipliers); +} + +/** + * Helper function for template_preprocess_responsive_image(). + * * Builds an array of attributes for tags to be used in a * tag. In other words, this function provides the attributes for each * tag in a tag. @@ -345,9 +371,6 @@ function template_preprocess_responsive_image(&$variables) { * See http://www.w3.org/html/wg/drafts/html/master/embedded-content.html#image-candidate-string * for further information. * - * @param \Drupal\Core\Image\ImageInterface $image - * (optional) The image to build the tags for. Optional and - * deprecated, should not be used so that it can be created when necessary. * @param array $variables * An array with the following keys: * - responsive_image_style_id: The \Drupal\responsive_image\Entity\ResponsiveImageStyle @@ -363,12 +386,16 @@ function template_preprocess_responsive_image(&$variables) { * @return \Drupal\Core\Template\Attribute[] * An array of attributes for the source tag. */ -function responsive_image_build_source_attributes(ImageInterface $image = NULL, array $variables, BreakpointInterface $breakpoint, array $multipliers) { - if (!$image && (empty($variables['width']) || empty($variables['height']))) { +function _responsive_image_build_source_attributes(array $variables, BreakpointInterface $breakpoint, array $multipliers) { + if ((empty($variables['width']) || empty($variables['height']))) { $image = \Drupal::service('image.factory')->get($variables['uri']); + $width = $image->getWidth(); + $height = $image->getHeight(); + } + else { + $width = $variables['width']; + $height = $variables['height']; } - $width = isset($variables['width']) && !empty($variables['width']) ? $variables['width'] : $image->getWidth(); - $height = isset($variables['height']) && !empty($variables['height']) ? $variables['height'] : $image->getHeight(); $extension = pathinfo($variables['uri'], PATHINFO_EXTENSION); $sizes = array(); $srcset = array();