-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SLB-296-quote-block-gutenberg' into dev
- Loading branch information
Showing
23 changed files
with
479 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/drupal/gutenberg_blocks/src/Plugin/Validation/GutenbergValidator/QuoteValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Drupal\gutenberg_blocks\Plugin\Validation\GutenbergValidator; | ||
|
||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\silverback_gutenberg\GutenbergValidation\GutenbergValidatorBase; | ||
|
||
/** | ||
* @GutenbergValidator( | ||
* id="quote_validator", | ||
* label = @Translation("Quote validator") | ||
* ) | ||
*/ | ||
class QuoteValidator extends GutenbergValidatorBase { | ||
use StringTranslationTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function applies(array $block): bool { | ||
return $block['blockName'] === 'custom/quote'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function validatedFields($block = []): array { | ||
return [ | ||
'quote' => [ | ||
'field_label' => $this->t('Quote text'), | ||
'rules' => ['required'], | ||
], | ||
'author' => [ | ||
'field_label' => $this->t('Quote author'), | ||
'rules' => ['required'], | ||
], | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { RichText } from 'wordpress__block-editor'; | ||
import { registerBlockType } from 'wordpress__blocks'; | ||
import { compose, withState } from 'wordpress__compose'; | ||
import { dispatch } from 'wordpress__data'; | ||
|
||
import { cleanUpText } from '../utils/clean-up-text'; | ||
import { DrupalMediaEntity } from '../utils/drupal-media'; | ||
|
||
declare const Drupal: { t: (s: string) => string }; | ||
|
||
const { t: __ } = Drupal; | ||
|
||
// @ts-ignore | ||
const { setPlainTextAttribute } = silverbackGutenbergUtils; | ||
|
||
// @ts-ignore | ||
registerBlockType(`custom/quote`, { | ||
title: __('Quote'), | ||
icon: 'format-quote', | ||
category: 'text', | ||
attributes: { | ||
quote: { | ||
type: 'string', | ||
}, | ||
author: { | ||
tpye: 'string', | ||
}, | ||
role: { | ||
type: 'string', | ||
}, | ||
mediaEntityIds: { | ||
type: 'array', | ||
}, | ||
}, | ||
// @ts-ignore | ||
edit: compose(withState())((props) => { | ||
return ( | ||
<blockquote> | ||
<RichText | ||
identifier="quote" | ||
value={props.attributes.quote} | ||
allowedFormats={['core/bold']} | ||
// @ts-ignore | ||
disableLineBreaks={false} | ||
placeholder={__('Quote')} | ||
keepPlaceholderOnFocus={false} | ||
onChange={(quote) => { | ||
props.setAttributes({ | ||
quote: cleanUpText(quote, ['strong']), | ||
}); | ||
}} | ||
/> | ||
<RichText | ||
identifier="author" | ||
className="quote-author" | ||
value={props.attributes.author} | ||
allowedFormats={[]} | ||
// @ts-ignore | ||
disableLineBreaks={false} | ||
placeholder={__('Author')} | ||
keepPlaceholderOnFocus={false} | ||
onChange={(author) => { | ||
setPlainTextAttribute(props, 'author', author); | ||
}} | ||
/> | ||
<RichText | ||
identifier="role" | ||
className="quote-role" | ||
value={props.attributes.role} | ||
allowedFormats={[]} | ||
// @ts-ignore | ||
disableLineBreaks={false} | ||
placeholder={__('Role')} | ||
keepPlaceholderOnFocus={false} | ||
onChange={(role) => { | ||
setPlainTextAttribute(props, 'role', role); | ||
}} | ||
/> | ||
<DrupalMediaEntity | ||
classname={'w-full'} | ||
attributes={{ | ||
...props.attributes, | ||
lockViewMode: true, | ||
allowedTypes: ['image'], | ||
}} | ||
setAttributes={props.setAttributes} | ||
isMediaLibraryEnabled={true} | ||
onError={(error) => { | ||
// @ts-ignore | ||
error = typeof error === 'string' ? error : error[2]; | ||
dispatch('core/notices').createWarningNotice(error); | ||
}} | ||
/> | ||
</blockquote> | ||
); | ||
}), | ||
save() { | ||
return null; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/drupal/test_content/content/file/2f1be18f-dc18-4b56-8ff0-ce24d8ff7df7.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
_meta: | ||
version: '1.0' | ||
entity_type: file | ||
uuid: 2f1be18f-dc18-4b56-8ff0-ce24d8ff7df7 | ||
default_langcode: en | ||
default: | ||
uid: | ||
- | ||
target_id: 1 | ||
filename: | ||
- | ||
value: the_silverback.jpeg | ||
uri: | ||
- | ||
value: 'public://2024-04/the_silverback.jpeg' | ||
filemime: | ||
- | ||
value: image/jpeg | ||
filesize: | ||
- | ||
value: 146269 | ||
status: | ||
- | ||
value: true | ||
created: | ||
- | ||
value: 1713785099 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions
74
packages/drupal/test_content/content/media/5dfc1856-e9e4-4f02-9cd6-9d888870ce1a.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
_meta: | ||
version: '1.0' | ||
entity_type: media | ||
uuid: 5dfc1856-e9e4-4f02-9cd6-9d888870ce1a | ||
bundle: image | ||
default_langcode: en | ||
depends: | ||
2f1be18f-dc18-4b56-8ff0-ce24d8ff7df7: file | ||
default: | ||
revision_user: | ||
- | ||
target_id: 1 | ||
status: | ||
- | ||
value: true | ||
uid: | ||
- | ||
target_id: 1 | ||
name: | ||
- | ||
value: the_silverback.jpeg | ||
created: | ||
- | ||
value: 1713785099 | ||
path: | ||
- | ||
alias: '' | ||
langcode: en | ||
pathauto: 0 | ||
content_translation_source: | ||
- | ||
value: und | ||
content_translation_outdated: | ||
- | ||
value: false | ||
field_media_image: | ||
- | ||
entity: 2f1be18f-dc18-4b56-8ff0-ce24d8ff7df7 | ||
alt: 'The silverback' | ||
title: '' | ||
width: 1280 | ||
height: 720 | ||
translations: | ||
de: | ||
status: | ||
- | ||
value: true | ||
uid: | ||
- | ||
target_id: 1 | ||
name: | ||
- | ||
value: the_silverback.jpeg | ||
created: | ||
- | ||
value: 1713785205 | ||
path: | ||
- | ||
alias: '' | ||
langcode: de | ||
pathauto: 0 | ||
content_translation_source: | ||
- | ||
value: en | ||
content_translation_outdated: | ||
- | ||
value: false | ||
field_media_image: | ||
- | ||
entity: 2f1be18f-dc18-4b56-8ff0-ce24d8ff7df7 | ||
alt: 'The silverback DE' | ||
title: '' | ||
width: 1280 | ||
height: 720 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fragment BlockQuote on BlockQuote { | ||
quote | ||
author | ||
role | ||
image { | ||
source(width: 1536, sizes: [[768, 768], [1536, 1536]]) | ||
alt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.