Skip to content

refactor: put all yard patterns related code together#71

Merged
laravdiemen merged 2 commits intomainfrom
refactor/yard-patterns
Feb 24, 2026
Merged

refactor: put all yard patterns related code together#71
laravdiemen merged 2 commits intomainfrom
refactor/yard-patterns

Conversation

@laravdiemen
Copy link
Copy Markdown
Contributor

@laravdiemen laravdiemen commented Feb 23, 2026

Aan de werking is eigenlijk niks veranderd, behalve dat de filter yard::gutenberg/enable-patterns nu wel daadwerkelijk goed werkt. Ik wil bijvoorbeeld bij Meedoen de Yard patronen uitschakelen omdat we daar via de code de patronen registeren. Toen ontdekte ik dat de code eigenlijk niet helemaal logisch was ingedeeld. In MenuManager stond alles wat met Yard Patronen te maken had. In PatternsManager stonden dingen die met Yard Patronen te maken hebben maar ook dingen die met de Wordpress patronen te maken hebben. Dus ik heb MenuManager hernoemd naar YardPatternsManager en daar ook de relevante code van de PatternsManager in gezet.

@laravdiemen laravdiemen force-pushed the refactor/yard-patterns branch from 4483e2d to 55acc51 Compare February 23, 2026 15:23
Comment on lines +11 to +23
\add_action('init', function () {
if (! apply_filters('yard::gutenberg/enable-patterns', true)) {
return;
}

$patternPostType = new PatternPostType();
$patternPostType->boot();

\add_action('admin_menu', [$this, 'registerAdminMenu']);
\add_action('enqueue_block_assets', [$this, 'enqueueMenuAssets']);
\add_filter('parent_file', [$this, 'highlightTaxSubMenu']);
\add_action('admin_init', [$this, 'registerAsBlockPatterns']);
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Om die apply_filters werkend te hebben moet het in een action zitten want direct in de boot werkt het niet. Ik weet alleen niet of dit nou de mooiste manier is. Als iemand nog een suggestie heeft om het mooier te krijgen, dan hoor ik dat graag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Een hook in een hook is inderdaad smelly. Ik zou deze init hook weghalen en een aparte functie maken:

private function isYardPatternsEnabled() {
	return apply_filters('yard::gutenberg/enable-patterns', true); 
}

En in in elk van de functies van deze class het checken doen:

if (! $this->isYardPatternsEnabled()) {
    return;
}

...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Moet je wel deze:

$patternPostType = new PatternPostType();
$patternPostType->boot();

naar een aparte functie doen, en wellicht wat omschrijven (zodat het in de init hook staat hier)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ik heb het aangepast, wel iets anders. Ik sla het op in isEnabled en die roep ik dan aan. Ik kreeg jouw voorstel om een of andere manier niet werkend maar dit is hetzelfde principe.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reorganizes all Yard-pattern–related functionality into a dedicated YardPatterns module and fixes the yard::gutenberg/enable-patterns filter so it actually disables the Yard patterns feature when set to false.

Changes:

  • Renames/moves the old menu/patterns responsibilities into YardPatternsManager and gates setup behind yard::gutenberg/enable-patterns.
  • Moves Yard “register as block patterns” logic out of Patterns\PatternManager into YardPatterns\YardPatternsManager.
  • Updates build/webpack entrypoints and generated assets from menuyard-patterns (CSS + asset files).

Reviewed changes

Copilot reviewed 8 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
webpack.config.js Renames the SCSS entrypoint to produce style-yard-patterns.css.
src/YardPatterns/resources/scss/style.scss Adds admin-menu icon sizing CSS for the Yard Patterns menu icon.
src/YardPatterns/resources/images/menu-logo.svg Adds an SVG asset for the menu icon.
src/YardPatterns/YardPatternsManager.php New central manager for Yard patterns: registers CPT/taxonomy, admin menu, assets, and block pattern registration (behind enable filter).
src/YardPatterns/PatternPostType.php Moves PatternPostType into the YardPatterns namespace.
src/PluginServiceProvider.php Switches provider bootstrapping from MenuManager to YardPatternsManager.
src/Patterns/PatternManager.php Removes Yard-pattern registration logic, leaving only “disable external/plugin patterns” behavior.
build/yard-patterns.js New/updated build artifact for the renamed entrypoint.
build/yard-patterns.asset.php New build asset manifest for the renamed entrypoint.
build/style-yard-patterns.css New compiled CSS for Yard Patterns admin menu styling.
build/style-yard-patterns-rtl.css RTL variant of the new compiled CSS.
build/menu.asset.php Removes obsolete asset manifest for the old menu entrypoint.
Comments suppressed due to low confidence (2)

src/YardPatterns/YardPatternsManager.php:138

  • get_the_terms() can return a WP_Error. The current ternary treats any truthy value as an array and will pass a WP_Error object into array_map, causing warnings/TypeErrors. Handle the error case explicitly (e.g., treat WP_Error as no terms).
    src/YardPatterns/YardPatternsManager.php:164
  • get_posts() uses the argument key order_by, but WordPress expects orderby. As-is, sorting by title will be ignored and patterns will be returned in the default order.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/YardPatterns/YardPatternsManager.php Outdated
\add_action('init', [$this, 'setYardPatternsEnabled']);
\add_action('init', [$this, 'registerYardPatternsPostType']);
\add_action('admin_menu', [$this, 'registerAdminMenu']);
\add_action('admin_enqueue_scripts', [$this, 'enqueueMenuAssets']);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@YvetteNikolov je had deze pas aangepast naar enqueue_block_assets maar dan wordt het niet in de admin ingeladen, alleen als je in de gutenberg editor zit maar de styling die hier nodig is, is juist buiten de gutenberg editor nodig. Dus volgens mij is dit in dit geval wel de juiste hook.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Je hebt gelijk, verander maar weer terug! Heb het te lomp veranderd zonder goed te kijken

@laravdiemen laravdiemen merged commit 1d4c2f5 into main Feb 24, 2026
@laravdiemen laravdiemen deleted the refactor/yard-patterns branch February 24, 2026 08:59
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.

4 participants