Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use "Page creation Patterns" for custom post types #41304

Closed
fabiankaegy opened this issue May 25, 2022 · 3 comments · Fixed by #41791
Closed

Add ability to use "Page creation Patterns" for custom post types #41304

fabiankaegy opened this issue May 25, 2022 · 3 comments · Fixed by #41791
Assignees
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced

Comments

@fabiankaegy
Copy link
Member

What problem does this address?

This would be a follow up from #38787. It is now possible to mark patterns as full page patterns by setting blockTypes to array( 'core/post-content' ). Currently this feature is limited to the Page post type however.

What is your proposed solution?

It would be great to also add support for custom post types to use the page creation patterns.

It would also be great to have a way to determine which patterns should get shown for which Post type. If I imagine a "Product" custom post type it would be super useful to only show various product-specific patterns that already use product CPT specific blocks in it.

At the same moment, it would be really valuable to have some programmatic way to opt-in or out of the modal altogether for certain post types.

@fabiankaegy fabiankaegy added the [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced label May 25, 2022
@Humanify-nl
Copy link

Great idea.

I think the reasoning why this isnt here for full page patterns in CPT's may be this:

Custom post types usually have a specific layout. We can already prefill post types with blocks when registering a post type with the 'template' array.

It would be amazing if we could refer to an existing pattern file here (from /patterns dir in theme). If we could add an array with two or more templates? We could auto fill the 'page creation modal' with a choice between two variations of the CPT template.

Proposed method of refering to template instead of block markup:

function myplugin_register_book_post_type() {
    $args = array(
        'public' => true,
        'label'  => 'Books',
        'show_in_rest' => true,
        'template' => 'post-book-pattern', // ( a php file which exists inside /patterns in theme)
        ),
    );
    register_post_type( 'book', $args );
}
add_action( 'init', 'myplugin_register_book_post_type' );

Proposed method with multiple pattern files.

function myplugin_register_book_post_type() {
    $args = array(
        'public' => true,
        'label'  => 'Books',
        'show_in_rest' => true,
        'template' => [ 'post-book-pattern', 'post-book-pattern-two' ]  // it is now an array, so page creation modal is triggered.
        ),
    );
    register_post_type( 'book', $args );
}
add_action( 'init', 'myplugin_register_book_post_type' );
Additionally:

A more abstract issue coupled with this is:

What is the difference between a 'template' and 'page-creation-pattern', in the eyes of a client / non-dev user?

These two concepts become a bit entangled and the more I think about this, the less it makes sense to make a distinction between a template and a full-page-pattern.

@jorgefilipecosta
Copy link
Member

Thank you all for the discussion that happened. I proposed an implementation for this issue at #41791.

@mtias
Copy link
Member

mtias commented Jun 17, 2022

I see this is the same proposal as #41398. @jorgefilipecosta take a look at the API I propose there, I think it's clearer.

@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants