diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index 2a0faeb..068f3ea 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -216,12 +216,12 @@ function template_preprocess_responsive_image(&$variables) { * can contain mapping definitions of mixed types (both 'image_style' and * 'sizes'). For example: * @code - * $responsiveImgMapping = entity_create('responsive_image_mapping', array( + * $responsive_img_mapping = ResponsiveImageMapping::create(array( * 'id' => 'mapping_one', * 'label' => 'Mapping One', * 'breakpoint_group' => 'responsive_image_test_module', * )); - * ->addMappingDefinition('responsive_image_test_module.mobile', '1x', array( + * $responsive_img_mapping->addMappingDefinition('responsive_image_test_module.mobile', '1x', array( * 'image_mapping_type' => 'image_style', * 'image_mapping' => 'thumbnail', * )) @@ -237,12 +237,11 @@ function template_preprocess_responsive_image(&$variables) { * )) * ->save(); * @endcode - * The above responsive image mapping will result in a tag similar to - * this: + * The above responsive image mapping will result in a tag like this: * @code * * - * + * * * * @endcode @@ -298,11 +297,8 @@ function template_preprocess_responsive_image(&$variables) { * * @endcode * - * The data structure we use to store the mapping information is a - * multidimensional array. The first level is the breakpoint, the second level - * is the multiplier. Since the specs do not allow width descriptors - * and multipliers combined inside one 'srcset' attribute, we either have to use - * something like + * Note: Since The specs do not allow width descriptors and multipliers combined + * inside one 'srcset' attribute, we either have to use something like * @code * * @endcode @@ -316,17 +312,17 @@ function template_preprocess_responsive_image(&$variables) { * multiplier) so the array contains an entry for breakpointA.1x and * breakpointA.2x. If we would output those we will end up with something like * @code - * + * * @endcode * which is illegal. So the solution is to merge both arrays into one and * disregard the multiplier. Which, in this case, would output * @code - * + * * @endcode * See http://www.w3.org/html/wg/drafts/html/master/embedded-content.html#image-candidate-string * for further information. * - * @param ImageInterface $image + * @param \Drupal\Core\Image\ImageInterface $image * The image to build the tags for. * @param array $variables * An array with the following keys: diff --git a/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php index beca8d2..bf15443 100644 --- a/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php +++ b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php @@ -62,10 +62,11 @@ class ResponsiveImageMapping extends ConfigEntityBase implements ResponsiveImage * Each mapping definition array contains the following keys: * - image_mapping_type: Either 'image_style' or 'sizes'. * - image_mapping: - * - If image_mapping_type is 'image_style', the image style ID. + * - If image_mapping_type is 'image_style', the image style ID (a + * string). * - If image_mapping_type is 'sizes', an array with following keys: - * - sizes: If image_mapping_type is 'sizes', the value for the - * 'sizes' attribute. + * - sizes: If image_mapping_type is 'sizes', the value for the 'sizes' + * attribute. * - sizes_image_styles: The image styles to use for the 'srcset' * attribute. * - breakpoint_id: The breakpoint ID for this mapping definition. @@ -98,14 +99,6 @@ public function __construct(array $values, $entity_type_id = 'responsive_image_m * {@inheritdoc} */ public function addMappingDefinition($breakpoint_id, $multiplier, array $mapping_definition) { - // Default 'image_mapping' to an empty string because the default for - // 'image_mapping_type' is 'image_style'. This means 'image_mapping' should - // be a string (the image style ID). If 'image_mapping_type' is 'sizes', the - // value for 'image_mapping' should be an array. - $defaults = array( - 'image_mapping_type' => 'image_style', - 'image_mapping' => '', - ); // If there is an existing mapping, overwrite it. foreach ($this->mapping_definitions as &$mapping) { if ($mapping['breakpoint_id'] === $breakpoint_id && $mapping['multiplier'] === $multiplier) { diff --git a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php index cdb5474..c668953 100644 --- a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php @@ -108,6 +108,9 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'container', ); $mapping_definition = $responsive_image_mapping->getMappingDefinition($breakpoint_id, $multiplier); + // @todo The image_mapping_type is only temporarily hardcoded, until + // support for the other responsive image mapping type ('sizes') is + // added in https://www.drupal.org/node/2334387. $form['keyed_mappings'][$breakpoint_id][$multiplier]['image_mapping_type'] = array( '#type' => 'value', '#value' => 'image_style', diff --git a/core/modules/responsive_image/src/ResponsiveImageMappingInterface.php b/core/modules/responsive_image/src/ResponsiveImageMappingInterface.php index b35a727..dd6aa54 100644 --- a/core/modules/responsive_image/src/ResponsiveImageMappingInterface.php +++ b/core/modules/responsive_image/src/ResponsiveImageMappingInterface.php @@ -100,7 +100,7 @@ public function getMappingDefinition($breakpoint_id, $multiplier); * Checks if there is at least one mapping definition defined. * * @param array $mapping_definition - * The mapping definition array. + * The mapping definition. * * @return bool * Whether the mapping definition is empty. @@ -114,8 +114,8 @@ public static function isEmptyMappingDefinition(array $mapping_definition); * The breakpoint ID. * @param string $multiplier * The multiplier. - * @param string $mapping_definition - * The mapping definition array. + * @param array $mapping_definition + * The mapping definition. * * @return $this */