Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: limit gutenberg html editing #393

Draft
wants to merge 2 commits into
base: release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/drupal/gutenberg_blocks/gutenberg_blocks.module
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ function gutenberg_blocks_form_node_form_alter(&$form, FormStateInterface $form_
'label' => $form->label(),
], $webforms);
$form['#attached']['drupalSettings']['customGutenbergBlocks']['forms'] = array_values($forms);

// Bind the html edit features to the 'administer content' permission.
$form['#attached']['drupalSettings']['gutenberg']['supportsHtml'] = Drupal::currentUser()->hasPermission('administer content');
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/drupal/gutenberg_blocks/js/customisations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
(() => {
window.DrupalGutenberg.defaultSettings.codeEditingEnabled =
drupalSettings.gutenberg.supportsHtml;
})();

drupalSettings.gutenberg._listeners.init.push(
// Remove some of the formatting options
function () {
Expand Down
12 changes: 12 additions & 0 deletions packages/drupal/gutenberg_blocks/js/filters/html-edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { addFilter } from 'wordpress__hooks';

addFilter(
'blocks.registerBlockType',
'custom/supportsHtml',
(settings: { supports: { html: boolean } }) => {
if (settings.supports) {
settings.supports.html = drupalSettings.gutenberg.supportsHtml;
}
return settings;
},
);
15 changes: 8 additions & 7 deletions packages/drupal/gutenberg_blocks/js/filters/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { PanelBody, SelectControl } from 'wordpress__components';
import { createHigherOrderComponent } from 'wordpress__compose';
import { addFilter } from 'wordpress__hooks';

const { t: __ } = Drupal;

addFilter(
'blocks.registerBlockType',
'custom/list',
Expand Down Expand Up @@ -41,14 +39,17 @@ addFilter<ComponentType>(
<BlockEdit {...props} />
{isSelected && name === 'core/list' && !ordered ? (
<InspectorControls>
<PanelBody title={__('List style')}>
<PanelBody title={Drupal.t('List style')}>
<SelectControl
value={props.attributes.customListStyle}
options={[
{ label: __('Bullets'), value: '' },
{ label: __('Arrows'), value: 'arrows' },
{ label: __('Checkmarks'), value: 'checkmarks' },
{ label: __('Question marks'), value: 'question-marks' },
{ label: Drupal.t('Bullets'), value: '' },
{ label: Drupal.t('Arrows'), value: 'arrows' },
{ label: Drupal.t('Checkmarks'), value: 'checkmarks' },
{
label: Drupal.t('Question marks'),
value: 'question-marks',
},
]}
onChange={(customListStyle: string) => {
setAttributes({
Expand Down
6 changes: 6 additions & 0 deletions packages/drupal/gutenberg_blocks/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import './blocks/form';
import './blocks/image-teaser';
import './blocks/image-teasers';
import './blocks/image-with-text';
import './filters/html-edit';
import './filters/list';
import './blocks/cta';
import './blocks/quote';
Expand All @@ -24,6 +25,10 @@ import { ComponentType } from 'react';
/* eslint-disable */

declare global {
interface Window {
DrupalGutenberg: any;
}

const Drupal: {
behaviors: any;
t: (s: string, t?: object) => string;
Expand All @@ -43,6 +48,7 @@ declare global {
const drupalSettings: {
gutenberg: any;
preview: any;
supportsHtml: boolean;
path: {
baseUrl: string;
pathPrefix: string;
Expand Down
Loading