diff --git a/packages/block-library/package.json b/packages/block-library/package.json index 8273630e6d72e..df844f5cf2939 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -29,7 +29,8 @@ "src/**/*.scss", "src/navigation-link/index.js", "src/template-part/index.js", - "src/query/index.js" + "src/query/index.js", + "src/quote/v2/index.js" ], "dependencies": { "@babel/runtime": "^7.16.0", diff --git a/packages/block-library/src/quote/v2/block.json b/packages/block-library/src/quote/v2/block.json deleted file mode 100644 index 6b0f4fc30cb24..0000000000000 --- a/packages/block-library/src/quote/v2/block.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, - "name": "core/quote", - "title": "Quote", - "category": "text", - "description": "Give quoted text visual emphasis. \"In quoting others, we cite ourselves.\" — Julio Cortázar", - "keywords": [ "blockquote", "cite" ], - "textdomain": "default", - "attributes": { - "attribution": { - "type": "string", - "source": "html", - "selector": "figcaption", - "default": "", - "__experimentalRole": "content" - } - } -} diff --git a/packages/block-library/src/quote/v2/index.js b/packages/block-library/src/quote/v2/index.js index 5d92e8302b91f..15bf94d3893dd 100644 --- a/packages/block-library/src/quote/v2/index.js +++ b/packages/block-library/src/quote/v2/index.js @@ -3,18 +3,14 @@ */ import { __ } from '@wordpress/i18n'; import { quote as icon } from '@wordpress/icons'; +import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ -import metadata from './block.json'; import edit from './edit'; import save from './save'; -const { name } = metadata; - -export { metadata, name }; - const settings = { icon, example: { @@ -35,3 +31,46 @@ const settings = { }; export default settings; + +/** + * This function updates the attributes for the quote v2. + * This should be moved to block.json when v2 becomes the default. + * + * @param {Array} blockSettings The settings of the block to be registered. + * @param {string} blockName The name of the block to be registered. + * @return {Array} New settings. + */ +function registerQuoteV2Attributes( blockSettings, blockName ) { + if ( ! window?.__experimentalEnableQuoteBlockV2 ) { + return blockSettings; + } + + if ( blockName !== 'core/quote' ) { + return blockSettings; + } + + // Register the new attribute. + Object.assign( blockSettings.attributes, { + attribution: { + type: 'string', + source: 'html', + selector: 'figcaption', + default: '', + __experimentalRole: 'content', + }, + } ); + + // Deregister the old ones. + delete blockSettings.attributes.value; + delete blockSettings.attributes.citation; + + return blockSettings; +} + +// Importing this file includes side effects. +// This has been declared in block-library/package.json under sideEffects. +addFilter( + 'blocks.registerBlockType', + 'core/quote/v2-attributes', + registerQuoteV2Attributes +);