Skip to content

Commit

Permalink
Use metadata object attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Apr 25, 2022
1 parent 1d028f4 commit 30ca4ac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
firstBlockName,
'__experimentalSection',
false
) && !! getBlockAttributes( clientId ).section,
) && !! getBlockAttributes( clientId ).metadata?.isSection,
};
},
[ clientIds, blocks, blockInformation?.icon ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ describe( 'BlockTitle', () => {
it( 'should return section title if the block supports it', () => {
useSelect.mockImplementation( () => ( {
name: 'name-with-section',
attributes: { section: { name: 'My custom section' } },
attributes: {
metadata: { name: 'My custom section', isSection: true },
},
} ) );

const wrapper = shallow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export default function useBlockDisplayTitle( clientId, maximumLength ) {

const sectionTitle =
hasBlockSupport( name, '__experimentalSection', false ) &&
attributes.section?.name;
attributes.metadata?.isSection &&
attributes.metadata?.name;

const label = sectionTitle || reusableBlockTitle || blockLabel;
// Label will fallback to the title if no label is defined for the current
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/hooks/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { hasBlockSupport } from '@wordpress/blocks';
*/
export function addAttribute( settings ) {
if ( hasBlockSupport( settings, '__experimentalSection', false ) ) {
// Allow blocks to specify their own section attribute definition with default value if needed.
if ( ! has( settings.attributes, [ 'section' ] ) ) {
// Allow blocks to specify their own metadata attribute definition with default value if needed.
if ( ! has( settings.attributes, [ 'metadata' ] ) ) {
settings.attributes = {
...settings.attributes,
section: {
metadata: {
type: 'object',
},
};
Expand Down

0 comments on commit 30ca4ac

Please sign in to comment.