diff --git a/packages/block-library/src/navigation-link/fallback-variations.js b/packages/block-library/src/navigation-link/fallback-variations.js deleted file mode 100644 index 008f2a53dd42e..0000000000000 --- a/packages/block-library/src/navigation-link/fallback-variations.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { - category as categoryIcon, - page as pageIcon, - postContent as postIcon, - tag as tagIcon, -} from '@wordpress/icons'; - -// FALLBACK: this is only used when the server does not understand the variations property in the -// register_block_type call. see navigation-link/index.php. -// Delete this file when supported WP ranges understand the `variations` property when passed to -// register_block_type in index.php. -const fallbackVariations = [ - { - name: 'link', - isDefault: true, - title: __( 'Custom Link' ), - description: __( 'A link to a custom URL.' ), - attributes: {}, - }, - { - name: 'post', - icon: postIcon, - title: __( 'Post Link' ), - description: __( 'A link to a post.' ), - attributes: { type: 'post', kind: 'post-type' }, - }, - { - name: 'page', - icon: pageIcon, - title: __( 'Page Link' ), - description: __( 'A link to a page.' ), - attributes: { type: 'page', kind: 'post-type' }, - }, - { - name: 'category', - icon: categoryIcon, - title: __( 'Category Link' ), - description: __( 'A link to a category.' ), - attributes: { type: 'category', kind: 'taxonomy' }, - }, - { - name: 'tag', - icon: tagIcon, - title: __( 'Tag Link' ), - description: __( 'A link to a tag.' ), - attributes: { type: 'tag', kind: 'taxonomy' }, - }, -]; - -/** - * Add `isActive` function to all `navigation link` variations, if not defined. - * `isActive` function is used to find a variation match from a created - * Block by providing its attributes. - */ -fallbackVariations.forEach( ( variation ) => { - if ( variation.isActive ) return; - variation.isActive = ( blockAttributes, variationAttributes ) => - blockAttributes.type === variationAttributes.type; -} ); - -export default fallbackVariations; diff --git a/packages/block-library/src/navigation-link/hooks.js b/packages/block-library/src/navigation-link/hooks.js index 2ec7a6105f5ad..57a942199e114 100644 --- a/packages/block-library/src/navigation-link/hooks.js +++ b/packages/block-library/src/navigation-link/hooks.js @@ -9,11 +9,6 @@ import { customPostType, } from '@wordpress/icons'; -/** - * Internal dependencies - */ -import fallbackVariations from './fallback-variations'; - function getIcon( variationName ) { switch ( variationName ) { case 'post': @@ -34,15 +29,6 @@ export function enhanceNavigationLinkVariations( settings, name ) { return settings; } - // Fallback handling may be deleted after supported WP ranges understand the `variations` - // property when passed to register_block_type in index.php. - if ( ! settings.variations ) { - return { - ...settings, - variations: fallbackVariations, - }; - } - // Otherwise decorate server passed variations with an icon and isActive function. if ( settings.variations ) { const isActive = ( blockAttributes, variationAttributes ) => { diff --git a/packages/block-library/src/navigation-link/test/__snapshots__/hooks.js.snap b/packages/block-library/src/navigation-link/test/__snapshots__/hooks.js.snap index 78ec18eeed097..7d3d333585193 100644 --- a/packages/block-library/src/navigation-link/test/__snapshots__/hooks.js.snap +++ b/packages/block-library/src/navigation-link/test/__snapshots__/hooks.js.snap @@ -1,98 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`hooks enhanceNavigationLinkVariations adds fallback variations when variations are missing 1`] = ` -Object { - "name": "core/navigation-link", - "one": "one", - "three": "three", - "two": "two", - "variations": Array [ - Object { - "attributes": Object {}, - "description": "A link to a custom URL.", - "isActive": [Function], - "isDefault": true, - "name": "link", - "title": "Custom Link", - }, - Object { - "attributes": Object { - "kind": "post-type", - "type": "post", - }, - "description": "A link to a post.", - "icon": - - , - "isActive": [Function], - "name": "post", - "title": "Post Link", - }, - Object { - "attributes": Object { - "kind": "post-type", - "type": "page", - }, - "description": "A link to a page.", - "icon": - - , - "isActive": [Function], - "name": "page", - "title": "Page Link", - }, - Object { - "attributes": Object { - "kind": "taxonomy", - "type": "category", - }, - "description": "A link to a category.", - "icon": - - , - "isActive": [Function], - "name": "category", - "title": "Category Link", - }, - Object { - "attributes": Object { - "kind": "taxonomy", - "type": "tag", - }, - "description": "A link to a tag.", - "icon": - - , - "isActive": [Function], - "name": "tag", - "title": "Tag Link", - }, - ], -} -`; - exports[`hooks enhanceNavigationLinkVariations enhances variations with icon and isActive functions 1`] = ` Object { "extraProp": "extraProp", diff --git a/packages/block-library/src/navigation-link/test/hooks.js b/packages/block-library/src/navigation-link/test/hooks.js index bf33b293ab691..de0b36f7ef9ba 100644 --- a/packages/block-library/src/navigation-link/test/hooks.js +++ b/packages/block-library/src/navigation-link/test/hooks.js @@ -26,18 +26,6 @@ describe( 'hooks', () => { three: 'three', } ); } ); - it( 'adds fallback variations when variations are missing', () => { - const updatedSettings = enhanceNavigationLinkVariations( - { - name: 'core/navigation-link', - one: 'one', - two: 'two', - three: 'three', - }, - 'core/navigation-link' - ); - expect( updatedSettings ).toMatchSnapshot(); - } ); it( 'enhances variations with icon and isActive functions', () => { const updatedSettings = enhanceNavigationLinkVariations( { diff --git a/packages/block-library/src/template-part/fallback-variations.js b/packages/block-library/src/template-part/fallback-variations.js deleted file mode 100644 index 089ec29f0bbfa..0000000000000 --- a/packages/block-library/src/template-part/fallback-variations.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { header as headerIcon, footer as footerIcon } from '@wordpress/icons'; -import { store as coreDataStore } from '@wordpress/core-data'; -import { select } from '@wordpress/data'; - -const fallbackVariations = [ - { - name: 'header', - icon: headerIcon, - title: __( 'Header' ), - description: __( - 'The Header template defines a page area that typically contains a title, logo, and main navigation.' - ), - attributes: { area: 'header' }, - scope: [ 'inserter' ], - }, - { - name: 'footer', - icon: footerIcon, - title: __( 'Footer' ), - description: __( - 'The Footer template defines a page area that typically contains site credits, social links, or any other combination of blocks.' - ), - attributes: { area: 'footer' }, - scope: [ 'inserter' ], - }, -]; - -fallbackVariations.forEach( ( variation ) => { - if ( variation.isActive ) return; - variation.isActive = ( blockAttributes, variationAttributes ) => { - const { area, theme, slug } = blockAttributes; - // We first check the `area` block attribute which is set during insertion. - // This property is removed on the creation of a template part. - if ( area ) return area === variationAttributes.area; - // Find a matching variation from the created template part - // by checking the entity's `area` property. - if ( ! slug ) return false; - const entity = select( coreDataStore ).getEntityRecord( - 'postType', - 'wp_template_part', - `${ theme }//${ slug }` - ); - return entity?.area === variationAttributes.area; - }; -} ); - -export default fallbackVariations; diff --git a/packages/block-library/src/template-part/variations.js b/packages/block-library/src/template-part/variations.js index ca862f5993ccc..d39b3e5e8a6bc 100644 --- a/packages/block-library/src/template-part/variations.js +++ b/packages/block-library/src/template-part/variations.js @@ -10,11 +10,6 @@ import { symbolFilled as symbolFilledIcon, } from '@wordpress/icons'; -/** - * Internal dependencies - */ -import fallbackVariations from './fallback-variations'; - function getTemplatePartIcon( iconName ) { if ( 'header' === iconName ) { return headerIcon; @@ -31,12 +26,6 @@ export function enhanceTemplatePartVariations( settings, name ) { return settings; } - // WordPress versions pre-5.8 do not support server side variation registration. - // So we must register the fallback variations until those versions are no longer supported. - if ( ! ( settings.variations && settings.variations.length ) ) { - return { ...settings, variations: fallbackVariations }; - } - if ( settings.variations ) { const isActive = ( blockAttributes, variationAttributes ) => { const { area, theme, slug } = blockAttributes;