diff --git a/packages/block-library/src/cover/block.json b/packages/block-library/src/cover/block.json
index c186a2416f5c9e..d2c55dd26b4d74 100644
--- a/packages/block-library/src/cover/block.json
+++ b/packages/block-library/src/cover/block.json
@@ -19,9 +19,6 @@
},
"alt": {
"type": "string",
- "source": "attribute",
- "selector": "img",
- "attribute": "alt",
"default": ""
},
"hasParallax": {
diff --git a/packages/block-library/src/cover/deprecated.js b/packages/block-library/src/cover/deprecated.js
index fc15cb4ac46d49..e2e773cace1426 100644
--- a/packages/block-library/src/cover/deprecated.js
+++ b/packages/block-library/src/cover/deprecated.js
@@ -244,6 +244,156 @@ const v12BlockSupports = {
},
};
+// Deprecation for blocks that does not have the aria-label when the image background is fixed or repeated.
+const v13 = {
+ attributes: v12BlockAttributes,
+ supports: v12BlockSupports,
+ save( { attributes } ) {
+ const {
+ backgroundType,
+ gradient,
+ contentPosition,
+ customGradient,
+ customOverlayColor,
+ dimRatio,
+ focalPoint,
+ useFeaturedImage,
+ hasParallax,
+ isDark,
+ isRepeated,
+ overlayColor,
+ url,
+ alt,
+ id,
+ minHeight: minHeightProp,
+ minHeightUnit,
+ tagName: Tag,
+ } = attributes;
+ const overlayColorClass = getColorClassName(
+ 'background-color',
+ overlayColor
+ );
+ const gradientClass = __experimentalGetGradientClass( gradient );
+ const minHeight =
+ minHeightProp && minHeightUnit
+ ? `${ minHeightProp }${ minHeightUnit }`
+ : minHeightProp;
+
+ const isImageBackground = IMAGE_BACKGROUND_TYPE === backgroundType;
+ const isVideoBackground = VIDEO_BACKGROUND_TYPE === backgroundType;
+
+ const isImgElement = ! ( hasParallax || isRepeated );
+
+ const style = {
+ minHeight: minHeight || undefined,
+ };
+
+ const bgStyle = {
+ backgroundColor: ! overlayColorClass
+ ? customOverlayColor
+ : undefined,
+ background: customGradient ? customGradient : undefined,
+ };
+
+ const objectPosition =
+ // prettier-ignore
+ focalPoint && isImgElement
+ ? mediaPosition(focalPoint)
+ : undefined;
+
+ const backgroundImage = url ? `url(${ url })` : undefined;
+
+ const backgroundPosition = mediaPosition( focalPoint );
+
+ const classes = classnames(
+ {
+ 'is-light': ! isDark,
+ 'has-parallax': hasParallax,
+ 'is-repeated': isRepeated,
+ 'has-custom-content-position':
+ ! isContentPositionCenter( contentPosition ),
+ },
+ getPositionClassName( contentPosition )
+ );
+
+ const imgClasses = classnames(
+ 'wp-block-cover__image-background',
+ id ? `wp-image-${ id }` : null,
+ {
+ 'has-parallax': hasParallax,
+ 'is-repeated': isRepeated,
+ }
+ );
+
+ const gradientValue = gradient || customGradient;
+
+ return (
+
+
+
+ { ! useFeaturedImage &&
+ isImageBackground &&
+ url &&
+ ( isImgElement ? (
+
+ ) : (
+
+ ) ) }
+ { isVideoBackground && url && (
+
+ ) }
+
+
+ );
+ },
+};
+
// Deprecation for blocks to prevent auto overlay color from overriding previously set values.
const v12 = {
attributes: v12BlockAttributes,
@@ -1673,4 +1823,4 @@ const v1 = {
},
};
-export default [ v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1 ];
+export default [ v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1 ];
diff --git a/packages/block-library/src/cover/edit/index.js b/packages/block-library/src/cover/edit/index.js
index 512794ee3f0ec8..5ff6f8a02ac140 100644
--- a/packages/block-library/src/cover/edit/index.js
+++ b/packages/block-library/src/cover/edit/index.js
@@ -534,7 +534,8 @@ function CoverEdit( {
) : (
) }
- { ! useFeaturedImage &&
- url &&
- isImageBackground &&
- isImgElement && (
-
- setAttributes( { alt: newAlt } )
- }
- help={
- <>
-
- { __(
- 'Describe the purpose of the image.'
- ) }
-
-
+ { ! useFeaturedImage && url && ! isVideoBackground && (
+
+ setAttributes( { alt: newAlt } )
+ }
+ help={
+ <>
+
{ __(
- 'Leave empty if decorative.'
+ 'Describe the purpose of the image.'
) }
- >
- }
- />
- ) }
+
+
+ { __( 'Leave empty if decorative.' ) }
+ >
+ }
+ />
+ ) }
) : (
diff --git a/test/integration/fixtures/blocks/core__cover__alt-fixed-background.html b/test/integration/fixtures/blocks/core__cover__alt-fixed-background.html
new file mode 100644
index 00000000000000..7c8aaa5a7ccbc6
--- /dev/null
+++ b/test/integration/fixtures/blocks/core__cover__alt-fixed-background.html
@@ -0,0 +1,5 @@
+
+
+
\ No newline at end of file
diff --git a/test/integration/fixtures/blocks/core__cover__alt-fixed-background.json b/test/integration/fixtures/blocks/core__cover__alt-fixed-background.json
new file mode 100644
index 00000000000000..d848174278dabe
--- /dev/null
+++ b/test/integration/fixtures/blocks/core__cover__alt-fixed-background.json
@@ -0,0 +1,35 @@
+[
+ {
+ "name": "core/cover",
+ "isValid": true,
+ "attributes": {
+ "url": "https://w.wiki/59So",
+ "useFeaturedImage": false,
+ "id": 612,
+ "alt": "Custom alt text",
+ "hasParallax": true,
+ "isRepeated": false,
+ "dimRatio": 50,
+ "backgroundType": "image",
+ "isDark": false,
+ "tagName": "div",
+ "layout": {
+ "type": "constrained"
+ }
+ },
+ "innerBlocks": [
+ {
+ "name": "core/paragraph",
+ "isValid": true,
+ "attributes": {
+ "align": "center",
+ "content": "",
+ "dropCap": false,
+ "placeholder": "Write title…",
+ "fontSize": "large"
+ },
+ "innerBlocks": []
+ }
+ ]
+ }
+]
diff --git a/test/integration/fixtures/blocks/core__cover__alt-fixed-background.parsed.json b/test/integration/fixtures/blocks/core__cover__alt-fixed-background.parsed.json
new file mode 100644
index 00000000000000..9de6f5b24fe0d0
--- /dev/null
+++ b/test/integration/fixtures/blocks/core__cover__alt-fixed-background.parsed.json
@@ -0,0 +1,37 @@
+[
+ {
+ "blockName": "core/cover",
+ "attrs": {
+ "url": "https://w.wiki/59So",
+ "id": 612,
+ "alt": "Custom alt text",
+ "hasParallax": true,
+ "dimRatio": 50,
+ "isDark": false,
+ "layout": {
+ "type": "constrained"
+ }
+ },
+ "innerBlocks": [
+ {
+ "blockName": "core/paragraph",
+ "attrs": {
+ "align": "center",
+ "placeholder": "Write title…",
+ "fontSize": "large"
+ },
+ "innerBlocks": [],
+ "innerHTML": "\n\n",
+ "innerContent": [
+ "\n\n"
+ ]
+ }
+ ],
+ "innerHTML": "\n\n",
+ "innerContent": [
+ "\n\n"
+ ]
+ }
+]
diff --git a/test/integration/fixtures/blocks/core__cover__alt-fixed-background.serialized.html b/test/integration/fixtures/blocks/core__cover__alt-fixed-background.serialized.html
new file mode 100644
index 00000000000000..438eba81614c4a
--- /dev/null
+++ b/test/integration/fixtures/blocks/core__cover__alt-fixed-background.serialized.html
@@ -0,0 +1,5 @@
+
+
+
diff --git a/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.html b/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.html
index 019385914ed580..8c77b25cf33fc5 100644
--- a/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.html
+++ b/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.html
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.parsed.json b/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.parsed.json
index 814565d144f08d..22ae61f6258ef7 100644
--- a/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.parsed.json
+++ b/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.parsed.json
@@ -29,9 +29,9 @@
]
}
],
- "innerHTML": "\n
\n ",
+ "innerHTML": "\n
\n ",
"innerContent": [
- "\n
",
+ "\n
\n "
]
diff --git a/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.serialized.html b/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.serialized.html
index 3af9171f1fa60c..e52c3e993dd109 100644
--- a/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.serialized.html
+++ b/test/integration/fixtures/blocks/core__cover__duotone-fixed-background.serialized.html
@@ -1,5 +1,5 @@
-