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

[WIP] Check if a block can be inserted when finding raw transforms #12799

Closed

Conversation

notnownikki
Copy link
Member

Fixes: #11245

Needs discussion on the approach, as this introduces a dependency from blocks to editor.

Description

When blocks are disabled, pasting content that matches their transforms should not insert them.

How has this been tested?

Disable the embed blocks, paste a URL. You should not get an embed block.

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@notnownikki notnownikki added the Needs Technical Feedback Needs testing from a developer perspective. label Dec 11, 2018
@notnownikki notnownikki self-assigned this Dec 11, 2018
@@ -285,6 +286,8 @@ export function findTransform( transforms, predicate ) {
* @return {Array} Block transforms for direction.
*/
export function getBlockTransforms( direction, blockTypeOrName ) {
const { canInsertBlockType } = select( 'core/editor' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a circular dependency between editor and blocks. The blocks module should not be aware of editor.

Can this be enforced from the editor module instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could introduce a filter, something like:

availableTransforms = applyFilters( 'blocks.transforms', transforms );

then the editor module could register a filter to remove any transforms to blocks that weren't allowed. How does that sound? It seems that this filtering does need to happen here, because if the editor gets a block type that isn't allowed, it doesn't have any information about what to do with it, because the content of the paragraph block that should be created instead could live in any attribute of the block that isn't allowed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative to a filter, could we pass as an additional argument an array of "available" block names which can be applied as a filter for the block type? I could see this might be made more difficult by the fact there are other functions within the blocks module which call getBlockTransforms, it's not just called by the editor module.

My worry with a filter might be that in mind of a refactor like proposed in #7119, there may be multiple editors present which each have their own set of limited blocks, which seems difficult/impossible to manage from a single filter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing in an argument would work for cases where editor needs a list of valid transforms, but pasteHandler from blocks is used in the RichText component to handle incoming pastes, and neither of these have a dependency on editor, and I figure that we don't want to introduce that either. So we'd have to have a new prop on RichText that was the list of allowed, or denied, block types, so that the RichText instances for the editor instance would have the right list. Does that seem right to you? It would mean altering every instantiation of a RichText component, wouldn't it?

@gziolo gziolo added the [Status] In Progress Tracking issues with work in progress label Jan 25, 2019
@gziolo gziolo removed this from the WordPress 5.x milestone Jan 25, 2019
Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @notnownikki, I guess we don't have this problem anymore, given that we now have a mechanism that ignores blocks in the replace action that cannot be inserted.

@youknowriad youknowriad deleted the fix/no-transforming-to-not-allowed-blocks branch May 27, 2020 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pasting links creates embed block when embed blocks are not allowed
5 participants