WordPress / wporg-gp-translation-events

Translation Events on WordPress.org
https://translate.wordpress.org/events/
GNU General Public License v2.0
13 stars 2 forks source link

Set up block theme #321

Closed psrpinto closed 2 months ago

psrpinto commented 3 months ago

This PR introduces a new block theme to be used for translation events, and potentially in the future for the whole of translate.wordpress.org (wporg-translate). For the moment, the theme is contained in this repository, but we can extract it into its own repository later, once/if we decide to use the theme for the rest of wporg-translate.

Before proceeding, please read the new theme's README, which contains valuable information that is useful to review this PR.

Summary of changes

How to review and test

  1. Pull translate-w-org-env and run the provision script again (it will take a while, probably). This is to get the changes introduced by:
  2. Make sure the Gutenberg plugin is installed/activated, and if not install/activate it
  3. Checkout this branch
  4. Set the TRANSLATION_EVENTS_NEW_DESIGN env variable to true
  5. Navigate to the "My Events" page
    • You should see the same as the screenshot below
  6. Navigate to other pages and make sure they look and function as they did

Screen capture

This is how a page looks when using the theme.

Screenshot 2024-07-10 at 15 03 10

TODO

psrpinto commented 3 months ago

After quite some effort and digging into WordPress internals of how themes are loaded, I've made some progress here but there are still some things to fix. See the Screen capture section in the PR description.

akirk commented 3 months ago

Fantastic! Looks like we're getting close!

akirk commented 2 months ago

Furthermore we can then replace the filter with just a block attribute: https://github.com/WordPress/wporg-gp-translation-events/commit/8ea412dd23fe7dac67cd7caedf40708e3c70a164

psrpinto commented 2 months ago

Great points @akirk! I'm working on incorporating your suggestions into this PR.

psrpinto commented 2 months ago

@akirk I've incorporated all suggestions you made:

I also took the liberty of adding a render_header( string $title ) convenience function so that individual pages don't need to do the wp_json_encode() and phpcs ignore dance.

psrpinto commented 2 months ago

I am unsure about your hesitation to just use do_blocks() over the whole PHP output, why is that?

This is something that I should've have explained earlier, apologies. The reason there can't be a single do_blocks() call over the entire page (header, page content, footer) is described as follows.

The header block calls wp_head(), which results in the styles that have been registered being output as <link> tags. Similarly, the footer block calls wp_footer() which will output the <script> tags.

This means that when do_blocks() is called on the header, all styles must have already been registered. Similar for footer and scripts.

So before calling do_blocks() on the header and footer, we must first call do_blocks() on the page content, so that styles and scripts required by the page content are registered.

A similar thing is done on the header block itself, because for example the local-navigation-bar block has its own styles. So we must call do_blocks() on it before the header calls wp_head().


There was actually an issue in the code you reviewed, because this behaviour wasn't happening: we were not correctly registering styles and scripts because we were not calling do_blocks() on the page content before the header/footer.

I've now pushed a commit that fixes this.

psrpinto commented 2 months ago

Just to add to what my comment above, the global-header-footer block uses a similar strategy: https://github.com/WordPress/wporg-mu-plugins/blob/trunk/mu-plugins/blocks/global-header-footer/blocks.php#L387-L421