diff --git a/packages/drupal/gutenberg_blocks/src/blocks/cta.tsx b/packages/drupal/gutenberg_blocks/src/blocks/cta.tsx new file mode 100644 index 000000000..ec6d9f7b4 --- /dev/null +++ b/packages/drupal/gutenberg_blocks/src/blocks/cta.tsx @@ -0,0 +1,93 @@ +import { + // @ts-ignore + __experimentalLinkControl as LinkControl, + RichText, +} from 'wordpress__block-editor'; +import { registerBlockType } from 'wordpress__blocks'; +import { ToggleControl } from 'wordpress__components'; +import { compose, withState } from 'wordpress__compose'; + +// @ts-ignore +const { t: __ } = Drupal; + +// @ts-ignore +const { setPlainTextAttribute } = silverbackGutenbergUtils; + +// @ts-ignore +registerBlockType('custom/cta', { + title: 'CTA', + icon: 'admin-links', + category: 'common', + attributes: { + url: { + type: 'string', + }, + text: { + type: 'string', + }, + // To have an easier integration with entity usage, we also retrieve and + // store the uuid of internal links. + uuid: { + type: 'string', + }, + openInNewTab: { + type: 'boolean', + }, + }, + // @ts-ignore + edit: compose(withState({}))((props) => { + return ( +
- - - + + + format: gutenberg summary: '' diff --git a/packages/drupal/test_content/content/node/ceb9b2a7-4c4c-4084-ada9-d5f6505d466b.yml b/packages/drupal/test_content/content/node/ceb9b2a7-4c4c-4084-ada9-d5f6505d466b.yml index 6ed97ed67..6c19a491d 100644 --- a/packages/drupal/test_content/content/node/ceb9b2a7-4c4c-4084-ada9-d5f6505d466b.yml +++ b/packages/drupal/test_content/content/node/ceb9b2a7-4c4c-4084-ada9-d5f6505d466b.yml @@ -65,6 +65,8 @@ default: + + format: gutenberg summary: '' diff --git a/packages/schema/src/schema.graphql b/packages/schema/src/schema.graphql index 232210302..9300972cb 100644 --- a/packages/schema/src/schema.graphql +++ b/packages/schema/src/schema.graphql @@ -198,6 +198,7 @@ union PageContent @resolveEditorBlockType = | BlockMedia | BlockForm | BlockImageTeasers + | BlockCta type BlockForm @type(id: "custom/form") { url: Url @resolveEditorBlockAttribute(key: "formId") @webformIdToUrl(id: "$") @@ -237,6 +238,12 @@ type BlockImageTeaser @default @value { ctaUrl: Url @resolveEditorBlockAttribute(key: "ctaUrl") } +type BlockCta @type(id: "custom/cta") { + url: Url @resolveEditorBlockAttribute(key: "url") + text: String @resolveEditorBlockAttribute(key: "text") + openInNewTab: Boolean @resolveEditorBlockAttribute(key: "openInNewTab") +} + input PaginationInput { limit: Int! offset: Int! diff --git a/tests/schema/specs/blocks.spec.ts b/tests/schema/specs/blocks.spec.ts index 90360da34..c542e5649 100644 --- a/tests/schema/specs/blocks.spec.ts +++ b/tests/schema/specs/blocks.spec.ts @@ -48,6 +48,11 @@ test('Blocks', async () => { ctaUrl } } + ... on BlockCta { + url + text + openInNewTab + } } } { @@ -132,6 +137,18 @@ test('Blocks', async () => { }, ], }, + { + "__typename": "BlockCta", + "openInNewTab": null, + "text": "Internal CTA", + "url": "/en/drupal", + }, + { + "__typename": "BlockCta", + "openInNewTab": true, + "text": "External CTA", + "url": "https://www.google.com", + }, { "__typename": "BlockMarkup", "markup": " @@ -174,6 +191,12 @@ test('Blocks', async () => { ", }, + { + "__typename": "BlockCta", + "openInNewTab": null, + "text": null, + "url": null, + }, ], "hero": { "__typename": "Hero",Quote DE
Citation DE