Open Lovor01 opened 10 months ago
When "type" is used along with "enum" in block.json, warnings and notices disappear. However, in that case, attribute might not be enum anymore.
Could you go into more detail on this? If you're referring to mixing types, it can be supported, for some core blocks templateLock
is declared like this:
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
}
The docs could be updated to be more accurate.
Potentially, the error could trigger here:
The line where the error gets printed:
In effect, one way to go about it would be to relax the requirement to include type
when enum
is defined.
When "type" is used along with "enum" in block.json, warnings and notices disappear. However, in that case, attribute might not be enum anymore.
Could you go into more detail on this? If you're referring to mixing types, it can be supported, for some core blocks
templateLock
is declared like this:"templateLock": { "type": [ "string", "boolean" ], "enum": [ "all", "insert", "contentOnly", false ] }
The docs could be updated to be more accurate.
I am not referring to mixing types. I wrote that declaring attribute as "enum" (without using "type" - that's what I understood from docs) issued a bunch of php errors. I provided example. Enum is array of numbers.
@Lovor01 I understand all that, but I'm referring to the quoted text ... you wrote this bit as well:
When "type" is used along with "enum" in block.json, warnings and notices disappear. However, in that case, attribute might not be enum anymore.
Which I don't understand, would you be able to help clarify what you mean in those specific sentences?
What I meant by that is that I am not familiar with internal functioning of attribute types. Enum type probably has some built-in validation (am I wrong?) by which it differs from normal type, otherwise I do not see the point of having enum. So if I use enum which is consisting of just numbers, like in my example, if I set type to number along with enum, the validation could be disabled in that case and I could set any number inside this attribute? I think the only point of having enum is validation, isn't it? And if you set enum, then type is irrelevant, like it says in docs, one or the other.
@Lovor01 I understand all that, but I'm referring to the quoted text ... you wrote this bit as well:
When "type" is used along with "enum" in block.json, warnings and notices disappear. However, in that case, attribute might not be enum anymore.
Which I don't understand, would you be able to help clarify what you mean in those specific sentences?
What I meant by that is that I am not familiar with internal functioning of attribute types. Enum type probably has some built-in validation (am I wrong?) by which it differs from normal type, otherwise I do not see the point of having enum. So if I use enum which is consisting of just numbers, like in my example, if I set type to number along with enum, the validation could be disabled in that case and I could set any number inside this attribute? I think the only point of having enum is validation, isn't it? And if you set enum, then type is irrelevant, like it says in docs, one or the other.
Thanks for explaining. Yes, I agree with that 👍
Description
If
enum
is used for variable value andtype
is not used (docs for attributes say:The attribute definition will contain, at a minimum, either a type or an enum.
), PHP throws a lot of Warnings and several NoticesStep-by-step reproduction instructions
In block.json, use enum for one property, without type, e.g.:
Compile block, enable debugging in wp-config.php:
define( 'WP_DEBUG', true );
Open site URL with block you created, you will get similar warnings and notices:
When "type" is used along with "enum" in block.json, warnings and notices disappear. However, in that case, attribute might not be enum anymore.
Screenshots, screen recording, code snippet
No response
Environment info
WordPress 6.4.2 Custom theme FF developer 122 Windows 10 Desktop, local environment
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes