Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

[DO NOT MERGE] Use category registration utility file in the patterns dir #124

Closed
wants to merge 13 commits into from

Conversation

mike-day
Copy link
Contributor

This is a modified approach built off #123. Instead of directly inserting the pattern registration calls in pattern files, this PR uses a utility file.


With this PR, when adding custom categories, the added code in the pattern file would look something like this:

Screenshot 2023-03-23 at 10 33 59 PM


Inserting registration calls directly in the pattern file (a la #123) would look something like this instead:

Screenshot 2023-03-23 at 3 31 39 PM


No testing needed yet. This is intended as experimentation to see if something like this is worth pursuing.

@mike-day
Copy link
Contributor Author

mike-day commented Mar 24, 2023

@kienstra as of right now, 4302348 and bb775a8 comprise the only new work in this PR.

I just started a new branch based off what you were already reviewing in #123.

@mike-day mike-day changed the base branch from main to try/add-new-categories-in-editor-ui March 24, 2023 03:53
…e core store to get registered categories instead of hydration
Comment on lines +58 to +59
// Add the utility file for custom category registration.
create_category_registration_file();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The registration file is written to /patterns/utilities/ each time the pattern is saved to file.

Maybe there is a more efficient way to approach this kind of idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think it's too much to maintain a separate utility file like this.

Also, it invites questions, like "Is it insecure that PM writes PHP to my theme?"

It's not insecure, but this is writing a lot of logic to PHP files.

I think a simple register_block_pattern_category() in a pattern file is fine.

But this is too abstract, in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you might be right — this might be getting a bit too abstract unnecessarily.

I like the idea of having a separate utility for this kind of thing, but we are actually writing this to themes, and a theme-maker might view this as being a bit overbearing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still, it's cool to know this is possible!

Comment on lines +464 to +470
/**
* Module Name: Pattern Category Utilities
* Description: This module contains functions for registering custom pattern categories.
* Namespace: PmPatternCategoryUtilities
*
* @package pattern-manager
*/
Copy link
Contributor Author

@mike-day mike-day Mar 24, 2023

Choose a reason for hiding this comment

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

This long of a header for the utility file might not be needed, but I do think it should be clear where the file came from (and that, ideally, it should not be deleted from the theme).

@mike-day mike-day changed the base branch from try/add-new-categories-in-editor-ui to main March 24, 2023 15:20
Comment on lines +60 to +62
/^pm_custom_category_/.test(
category.value
);
Copy link
Contributor Author

@mike-day mike-day Mar 24, 2023

Choose a reason for hiding this comment

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

Parsing to find which registered categories are custom (and from PM) is a bit tricky.

Initially, I tried adding another array item called pm_meta to the registration call, but querying registered categories from either the core data store (or via a PHP call to the category registry) does not always return the custom item.

Prepending the value (registered as name) with a custom string and checking against it has been the only reliable method I've found to fix this issue for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The drawback to this method — if the utility file is deleted for some reason, custom category labels will be ugly.

@mike-day
Copy link
Contributor Author

Closed in favor of #123.

@mike-day mike-day closed this May 19, 2023
@mike-day mike-day deleted the try/category-registration-utility-file branch May 19, 2023 19:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants