Skip to content

Commit

Permalink
Add metadata in button transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Feb 19, 2024
1 parent 435cd73 commit 7b753e1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/block-library/src/buttons/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ const transforms = {
{},
// Loop the selected buttons.
buttons.map( ( attributes ) => {
const element = createElement(
document,
attributes.content
);
const { content, metadata } = attributes;
const element = createElement( document, content );
// Remove any HTML tags.
const text = element.innerText || '';
// Get first url.
const link = element.querySelector( 'a' );
const url = link?.getAttribute( 'href' );
// Adapt bindings to the button block.
if ( metadata?.bindings?.content ) {
metadata.bindings.text = metadata.bindings.content;
delete metadata.bindings.content;
}
// Create singular button in the buttons block.
return createBlock( 'core/button', {
text,
url,
metadata,
} );
} )
),
Expand Down

0 comments on commit 7b753e1

Please sign in to comment.