Skip to content

Feat/php only blocks - #102

Open
Yannicvanveen wants to merge 6 commits into
mainfrom
feat/php-only-blocks
Open

Feat/php only blocks#102
Yannicvanveen wants to merge 6 commits into
mainfrom
feat/php-only-blocks

Conversation

@Yannicvanveen

Copy link
Copy Markdown

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are verified runtime/behavioral issues in the new filtering and build-exclusion logic (type safety in AllowedBlocks, unsafe webpack pattern mutation) and the new block.json textdomain is misconfigured for translations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds support for “PHP-only blocks” that are registered directly from src/PhpBlocks (no webpack build step), including a new yard/greeting block, and updates the build/config/docs to keep these blocks out of build/ while still participating in the plugin’s allowed-blocks filtering.

Changes:

  • Add PHP-only block infrastructure (PhpBlockManager, BlockViewModel, BladeRenderer) and a first PHP-only block (Greeting).
  • Centralize yard::gutenberg/allowed-blocks filtering via Support\AllowedBlocks and apply it to both built and PHP-only blocks.
  • Update webpack config to exclude src/PhpBlocks/** from the wp-scripts copy/manifest flow; update documentation and metadata versions.
File summaries
File Description
webpack.config.js Adjusts webpack plugin patterns to ignore src/PhpBlocks/** so PHP-only blocks don’t leak into build/ manifests.
src/Support/AllowedBlocks.php New helper to apply yard::gutenberg/allowed-blocks consistently across block sources.
src/PluginServiceProvider.php Registers PhpBlockManager and routes built block registration through AllowedBlocks.
src/PhpBlocks/PhpBlockManager.php Discovers and registers PHP-only blocks from src/PhpBlocks/* with server-side rendering.
src/PhpBlocks/Greeting/style.css Adds styling for the yard/greeting PHP-only block.
src/PhpBlocks/Greeting/Greeting.php Implements the Greeting block’s view model logic and period selection/filtering.
src/PhpBlocks/Greeting/greeting.blade.php Blade template for the Greeting block output.
src/PhpBlocks/Greeting/block.json Block metadata for yard/greeting (autoRegister + style).
src/PhpBlocks/BlockViewModel.php Base view model providing compose/override/classes and wrapper attribute handling.
src/PhpBlocks/BladeRenderer.php Renders block templates via the host theme’s Blade view factory with safe fallback behavior.
readme.txt Updates “Tested up to” to 7.0.
README.MD Documents PHP-only block structure, behavior, and new greeting-periods filter.
package-lock.json Updates lockfile package version to 1.8.0.
Review details
  • Files reviewed: 12/13 changed files
  • Comments generated: 5
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread webpack.config.js
Comment on lines +32 to +47
config.plugins.forEach( ( plugin ) => {
if ( ! Array.isArray( plugin?.patterns ) ) {
return;
}

plugin.patterns = plugin.patterns.map( ( pattern ) => ( {
...pattern,
globOptions: {
...pattern.globOptions,
ignore: [
...( pattern.globOptions?.ignore ?? [] ),
'**/PhpBlocks/**',
],
},
} ) );
} );
Comment on lines +2 to +12
.wp-block-yard-greeting {
color: var( --yard-greeting-color, inherit );
font-size: var( --yard-greeting-font-size, inherit );
line-height: var( --yard-greeting-line-height, inherit );

&:has(.wp-block-yard-greeting__suffix) {
display: flex;
flex-direction: column;
row-gap: var( --yard-greeting-spacing, 0 );
}
}
Comment on lines +31 to +38
$allowedBlocks = \apply_filters('yard::gutenberg/allowed-blocks', []);

return array_filter(
$blockNames,
function (string $blockName) use ($allowedBlocks) {
return in_array($blockName, $allowedBlocks);
}
);
if (! isset(self::$reported[$templatePath])) {
self::$reported[$templatePath] = true;

\_doing_it_wrong(__METHOD__, \esc_html($message), '1.8.0');
"category": "yard",
"icon": "smiley",
"description": "Toont een begroeting.",
"textdomain": "yard",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants