Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[5.x] Add support for collection entry blueprints loaded via addons #11674

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

Closed
xenco wants to merge 2 commits into statamic:5.x from xenco:feat/entry-blueprints

Conversation

Copy link

@xenco xenco commented Apr 7, 2025
edited by duncanmcclean
Loading

This PR enables addons to supply predefined blueprints for existing collections.

Closes statamic/ideas#1327.

Problem
Statamic previously introduced addon blueprint loading support (see #9324), but it was limited to top-level blueprints only. It did not allow addons to add blueprints to existing collections—for example, adding an extra blueprint to the "pages" collection to support features like a page builder with addon-provided and autoloaded fieldsets.

Solution
This PR extends the blueprint loading mechanism, enabling addons to load entry blueprints for any existing collection. To make use of this functionality, addons must follow this directory structure:

Addon Root
└── resources/
 └── blueprints/
 └── collections/
 └── {collection-handle}/
 └── {blueprint-name}.yaml

Which will result in the addon blueprints being visible and selectable for that collections entries.

Copy link
Member

It looks like this has caused a bunch of test failures. Would you be able to take a look?

Most of them are the same error:

CleanShot 2025年04月07日 at 13 07 22

Copy link
Author

xenco commented Apr 7, 2025

I think the errors are caused by where I initially placed the changes. Although the modifications were only relevant for collections, they unintentionally affected all blueprints.
Additionally, the tests aren't configured yet to handle the new method addonEntryBlueprints in the Blueprint Facade.
I've now moved the logic directly into the collection and the tests run fine locally.

Sorry if this caused confusion or still is not the right way of doing things. It's my first time working with the core.
I hope my explanation makes sense and this change can be integrated into the codebase.

Copy link
Member

No worries!

Copy link
Contributor

edalzell commented Apr 7, 2025

How is this different than the addon use the blueprint found event?

Copy link
Author

xenco commented Apr 8, 2025
edited
Loading

Hi @edalzell, if existing functionality already covers my use case, could you please provide me with an example?

Just registering the blueprints to a namespace does not work for me. I tried multiple variations of namespace and path. Still only the top-level blueprints are registered.

public function bootAddon()
{
 Blueprint::addNamespace("collections.pages", base_path('resources/blueprints/collections/pages'));
}

Copy link
Contributor

Hi, while I like this change very much since I have the same problem as well it leads to inconsistent behavior.
Example: The package myPackage wants to add a customPages Blueprint to the Pages Collection. If this Blueprint is changed and saved in the cp Statamic will create a New Blueprint in resources/blueprints/collections/pages/my_package_custom_pages.yaml.

This changed blueprint will NOT be used and will be overwritten by the plugins blueprint.

I would argue that similar to similar to Laravel Standard and how Fieldsets are handled the customized Blueprint should land in resources/blueprints/vendors/myPackage/collections/pages/custompage.yaml and override plugins blueprint.

Copy link
Member

If existing functionality already covers my use case, could you please provide me with an example?

Addons can currently listen to the EntryBlueprintFound event, which allows them to ensure/append fields before the blueprint is rendered in the CP.

For example:

<?php
namespace App\Listeners;
use Statamic\Events\EntryBlueprintFound;
class AddExtraFields
{
 /**
 * Create the event listener.
 */
 public function __construct()
 {
 //
 }
 /**
 * Handle the event.
 */
 public function handle(EntryBlueprintFound $event): void
 {
 $event->blueprint->ensureField('example_field', [
 'type' => 'text',
 'display' => 'Example field',
 ]);
 }
}

Addons can also register publishables, allowing users to copy files (like blueprint YAML files) using Laravel's vendor:publish command.

The Blueprint::addNamespace() method is intended for addons who wish to make their own blueprints, separate from collection blueprints.

Copy link
Member

Thanks for the PR and sorry for the delay. Your addon could publish a blueprint yaml file to resources/vendor/collections/{collection}/{blueprint}.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add support for collection entry blueprints loaded via addons

AltStyle によって変換されたページ (->オリジナル) /