gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

customTemplates: unable to remove postType support

Open ramizmanked opened this issue 4 years ago • 3 comments

Description

I'm unable to remove postType support from customTemplates.postTypes in theme.json.

For instance, I want to use Blank template only in postType: Page (not Post). Here is snippet from theme.json: "customTemplates": [ { "name": "blank", "title": "Blank", "postTypes": [ "page" ] } ]

Step-by-step reproduction instructions

Covered in screen recording below

Screenshots, screen recording, code snippet

https://vimeo.com/699696593/52f8185e33

Environment info

  • WordPress: 5.9.3
  • Gutenberg: 13.0.0
  • Theme: TwentyTwentyTwo/-Child
  • Google Chrome: 100.0.4896.88
  • System Configuration: Mac with Apple Silicon running on macOs Monterey 12.3

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

ramizmanked avatar Apr 15 '22 06:04 ramizmanked

I think this is a logic issue when merging the child theme.json, and I looked into how theme.json is merged.

From the description of the merge logic in theme.json, a simple array should be replaced by the child theme's values.

The array_replace_recursive algorithm merges at the leaf level, but we don't want leaf arrays to be merged, so we overwrite it.

For leaf values that are sequential arrays it will use the numeric indexes for replacement. We rather replace the existing with the incoming value, if it exists. This is the case of spacing.units.

For leaf values that are associative arrays it will merge them as expected. This is also not the behavior we want for the current associative arrays (presets). We rather replace the existing with the incoming value, if it exists. This happens, for example, when we merge data from theme.json upon existing theme supports or when we merge anything coming from the same source twice. This is the case of color.palette, color.gradients, color.duotone, typography.fontSizes, or typography.fontFamilies.

Additionally, for some preset types, we also want to make sure the values they introduce don't conflict with default values. We do so by checking the incoming slugs for theme presets and compare them with the equivalent default presets: if a slug is present as a default we remove it from the theme presets.

As per this explanation, I think that even for simple arrays other than spacing.units, they should be replaced by the child theme values.

The following three properties are applicable:

  • customTemplates.postTypes
  • settings.color.duotone.colors
  • patterns

t-hamano avatar Apr 16 '22 14:04 t-hamano

Related Issue: #40557

t-hamano avatar Apr 26 '22 02:04 t-hamano

@ramizmanked I would like to close this issue to consolidate the discussion to #40557. If you have any issues, please don't mind to comment.

t-hamano avatar May 28 '22 11:05 t-hamano