-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Enable filter hooks for convertLegacyBlockNameAndAttributes #40749
Enable filter hooks for convertLegacyBlockNameAndAttributes #40749
Conversation
Thanks for contributing, @ddryo. We're trying to avoid introducing new JS hooks in the Gutenberg plugin whenever possible. See #35757 (comment). You can also find a general discussion for extensibility here - #37448. |
So what if I want to do the same thing with custom blocks as with Just having hooks here can greatly reduce maintenance costs for many developers. I think the necessary hooks should be implemented. |
One of the serious problems with publishing custom blocks as plugins, etc., is the high development costs involved in changing functionality. It is impossible to design a perfect design from the start so that there are no changes to the specification at all. This is because the Gutenberg core is constantly evolving and changing. Important components are changed, deprecated, or new and useful components and APIs are created. This hook can be useful when trying to keep up with changes in the core and adjust blocks developed in the past to make them even better. Of course, in many cases, the I also expect that there will be many cases where it will be easier to update the Translated with www.DeepL.com/Translator (free version) |
@Mamaduka is that project policy? I'm definitely in favor of adding new hooks to make things more extensible even if they are implicit. WordPress itself is fairly implicit and while ugly that has been one of its strength IMO. This seems like a valuable solution solving a known problem; did you have an alternate idea for implementation? |
Hm. I'm not seeing what you are seeing in either of the linked issues/PRs. This proposal is so far away from the kind of thing I think @nerrad was talking about too that I don't see it applying (correct me if I'm wrong please). We've made intentional choices to extend flows over location, but there's a lot of data-side extensibility we rely on which is very technical in nature. Renaming a block seems like one of them since that's not possible through the block deprecation process. We might argue that we should make block deprecation support renaming, but that seems like opening a can of worms to avoid something that's otherwise normal and reasonable. |
I just want to be clear that I've nothing against this solution. @dmsnell, I was under the impression that introducing new hooks were discouraged in the project, but I probably miss interpreted @nerrad's and @youknowriad's comments 😅 Side note: I think it would be nice to have the project's extensibility policy/approach documented somewhere. |
The challenge with introducing a new filter is that the internal function, like
We discussed that in the past, and the outcome was that it isn't a common use case to rename the block so we rather keep it limited for core blocks to ensure backward compatibility is kept. However, the proposal to make it filterable sounds reasonable if that would be useful also for other blocks. |
@@ -67,5 +72,8 @@ export function convertLegacyBlockNameAndAttributes( name, attributes ) { | |||
name = 'core/comment-date'; | |||
} | |||
|
|||
return [ name, newAttributes ]; | |||
return applyFilters( 'editor.convertLegacyBlockNameAndAttributes', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we document the filter in the code with JSDoc? For reference, this is how filters get documented in WordPress core:
We should also include a new section in this document:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great. Cc @ryanwelcher.
hi @ddryo 👋 I'm looking forward to seeing these changes merged, too <3 Are you going to continue with the remaining issues? could I help here? |
hi @ddryo it's me again 😅 I'd do want to merge your PR rather than mine. But also, I'd like to move on with other stuff that is based on this hook. So let's wait a little bit more until asking dev folks to start to consider using this alternative PR. |
Sorry, the negative comments came first, so I gave up thinking it was closed and didn't check for a long time. Is this PR still alive? |
I'm not sure, to be honest. I think it's worth it but we should as to core folks. |
I understand the motivation for this change (and thank you for the diff), but I'm apprehensive about it. Indeed, blocks evolve over time, and the Block API accounts for this via validation, attribute migration, etc. However, all this takes place within the relative safety of each block type, which acts both as a namespace and as an error boundary. The underlying assumption here is that block names are stable. Yes, there have been times over the years when Core needed to rename some its own blocks, but I guess we've lived and learned over five and a half years. The fact that I'd encourage contributors to:
|
Let's close this PR, as it needs more info to be actionable. Please feel free to reopen again if there is more information. 🙏 |
What? & Why?
Enable filter hooks for
convertLegacyBlockNameAndAttributes
.While
convertLegacyBlocks
only has the core blocks available.This PR allows plugin creators to change their block names.
For example, the following code would change
my-plugin/example-block
tomy-addon/example-block
.This can solve problems such as #17372.