WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.32k stars 4.12k forks source link

Media-text Block Customization mediaWidth Not Applying in theme.json File #64358

Open janmckell opened 1 month ago

janmckell commented 1 month ago

Description

The default mediaWidth setting for the Media & Text block does not change when updated in the theme.json file of a block theme.

Step-by-step reproduction instructions

  1. Install or activate a Block theme (e.g., Twenty Twenty-Four or Twenty Twenty-Three).
  2. Edit the theme’s theme.json file to set block-level settings for the Media & Text block to change the default mediaWidth.
  3. Check the block’s settings in the editor to see if the default mediaWidth has changed.

Expected Result: The default mediaWidth should update to the new value set in the theme.json file.

Actual Result: The default mediaWidth remains at 50, even after clearing the cache and switching themes back and forth.

Code Snippet from theme.json:

{
  "settings": {
    "blocks": {
      "core/media-text": {
        "mediaWidth": {
          "type": "number",
          "default": 60
        }
      }
    }
  }
}

Also tested:

"core/media-text": {
        "custom": {
          "mediaWidth": 60
        }
      }

and this:

            "core/media-text": {
        "attributes": {
          "mediaWidth": {
            "type": "number",
            "default": 60
          }
        }
      }

Screenshots, screen recording, code snippet

Markup on 2024-08-07 at 3:45:20 PM

Environment info

– WordPress 6.6.1 – Tested with no Gutenberg plugin – Also tested with Gutenberg Version 18.9.0 – Browser: Chrome - Version 127.0.6533.90 – Theme: Twenty Twenty-Four and Twenty Twenty-Three – macOS

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Rishit30G commented 1 month ago

Hi @janmckell I was trying to replicate the issue in TT4 theme, but looks like the code snippet you provided might not be a part of theme.json If we want to alter the mediaWidth setting for the Media & Text block, then we should be updating the mediaWidth property in the block.json The file can be found by following this path in the codebase: packages > block-library > src > media-text > block.json Here is screencast of the expected results after updating it with a new value:

https://github.com/user-attachments/assets/4a072f95-92f3-4582-bf31-87818443a2b4

So I believe in a similar way we can create a block.json and insert the attributes as per our needs

janmckell commented 1 month ago

Hey @Rishit30G

Thank you so much for testing this. :) Okay, I see that this can be set inside the Gutenberg plugin at: build/block-library/blocks/media-text/block.json and by editing the attribute, 'mediaWidth' to the new default number.

Doing it this way isn't a very sustainable option since anytime the Gutenberg plugin is updated, this would be overwritten :( ...so the idea was to determine how it could be set at the block level and from within the theme folder itself.

carolinan commented 1 month ago

Hi This is the expected result, media width is not supported in theme.json. Kindly refer to the theme.json reference for all supported settings and style options. https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/

Because of this, I am changing the label from bug to enhancement, so that this may be added in the future.

janmckell commented 1 month ago

Hi This is the expected result, media width is not supported in theme.json. Kindly refer to the theme.json reference for all supported settings and style options. https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/

Because of this, I am changing the label from bug to enhancement, so that this may be added in the future.

@carolinan Noted, and thank you very much!!!