diff --git a/core/modules/responsive_image/config/schema/responsive_image.schema.yml b/core/modules/responsive_image/config/schema/responsive_image.schema.yml index 75b1d83..27acfa6 100644 --- a/core/modules/responsive_image/config/schema/responsive_image.schema.yml +++ b/core/modules/responsive_image/config/schema/responsive_image.schema.yml @@ -10,11 +10,11 @@ responsive_image.mappings.*: label: type: label label: 'Label' - mapping_definitions: + mappingDefinitions: type: sequence label: 'Mapping definitions' sequence: - - type: mapping + - type: mapping_definition label: 'Mapping definition' mapping_definition: # Image mapping type. Either 'sizes' (using the 'sizes' attribute) diff --git a/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php index 3103e4c..9a60f23 100644 --- a/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php +++ b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php @@ -57,21 +57,28 @@ class ResponsiveImageMapping extends ConfigEntityBase implements ResponsiveImage protected $label; /** - * The responsive image mappings. + * The responsive image mapping definitions. * - * Each responsive mapping array contains the following keys: - * - breakpoint_id - * - multiplier - * - image_style + * 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 'sizes', an array with following keys: + * - 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. + * - multiplier: The multiplier for this mapping definition. * * @var array */ - protected $mappings = array(); + protected $mappingDefinitions = array(); /** * @var array */ - protected $keyedMappings; + protected $keyedMappingDefinitions; /** * The responsive image breakpoint group. @@ -96,7 +103,7 @@ public function addMappingDefinition($breakpoint_id, $multiplier, array $mapping 'image_mapping' => '', ); // If there is an existing mapping, overwrite it. - foreach ($this->mappings as &$mapping) { + foreach ($this->mappingDefinitions as &$mapping) { if ($mapping['breakpoint_id'] === $breakpoint_id && $mapping['multiplier'] === $multiplier) { $mapping = array( 'breakpoint_id' => $breakpoint_id, @@ -105,11 +112,11 @@ public function addMappingDefinition($breakpoint_id, $multiplier, array $mapping return $this; } } - $this->mappings[] = array( + $this->mappingDefinitions[] = array( 'breakpoint_id' => $breakpoint_id, 'multiplier' => $multiplier, ) + $mapping_definition + $defaults; - $this->keyedMappings = NULL; + $this->keyedMappingDefinitions = NULL; return $this; } @@ -125,33 +132,34 @@ public function hasMappingDefinitions() { * {@inheritdoc} */ public function getKeyedMappingDefinitions() { - if (!$this->keyedMappings) { - $this->keyedMappings = array(); - foreach($this->mappings as $mapping) { + if (!$this->keyedMappingDefinitions) { + $this->keyedMappingDefinitions = array(); + foreach($this->mappingDefinitions as $mapping) { if (!$this->isEmptyMappingDefinition($mapping)) { // Only return the selected image styles. if ($mapping['image_mapping_type'] == 'sizes') { $mapping['image_mapping']['sizes_image_styles'] = array_filter($mapping['image_mapping']['sizes_image_styles']); } - $this->keyedMappings[$mapping['breakpoint_id']][$mapping['multiplier']] = $mapping; + $this->keyedMappingDefinitions[$mapping['breakpoint_id']][$mapping['multiplier']] = $mapping; } } } - return $this->keyedMappings; + return $this->keyedMappingDefinitions; } /** * {@inheritdoc} */ public function getMappingDefinitions() { - return $this->get('mappings'); + return $this->get('mappingDefinitions'); } /** * {@inheritdoc} */ public function setBreakpointGroup($breakpoint_group) { - // If the breakpoint group is changed then the mappings are invalid. + // If the breakpoint group is changed then the mapping definitions are + // invalid. if ($breakpoint_group !== $this->breakpointGroup) { $this->removeMappingDefinitions(); } @@ -170,8 +178,8 @@ public function getBreakpointGroup() { * {@inheritdoc} */ public function removeMappingDefinitions() { - $this->mappings = array(); - $this->keyedMappings = NULL; + $this->mappingDefinitions = array(); + $this->keyedMappingDefinitions = NULL; return $this; }