Skip to content

Commit

Permalink
Quote v2: update how attrs are registered (#39729)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal authored Mar 25, 2022
1 parent 2943570 commit 4b73536
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
3 changes: 2 additions & 1 deletion packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 0 additions & 19 deletions packages/block-library/src/quote/v2/block.json

This file was deleted.

49 changes: 44 additions & 5 deletions packages/block-library/src/quote/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
);

0 comments on commit 4b73536

Please sign in to comment.