-
Notifications
You must be signed in to change notification settings - Fork 11
Add support for registering globals with both Eloquent and Stache drivers #73
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
Conversation
…oquent Driver for globals Co-authored-by: tdwesten <[email protected]>
… hook Co-authored-by: tdwesten <[email protected]>
|
@copilot I now see the challange is bigger, we need a way to register globals from the statamic builder, but statamic uses globals and globals sets. Deep think how we can do this. Now the registered globals (in the current state of the code/repo) do not show up. review the statamic code for globals and there implementation. Succes is when we can register the globals from code, like we do with the blueprints. |
I understand the issue now. The challenge is that I'll fix the Working on the fix now. |
…atabase globals Co-authored-by: tdwesten <[email protected]>
Co-authored-by: tdwesten <[email protected]>
|
@copilot Oke so we need also a way to register and global sets i think |
You're correct - we're already registering global sets (the containers). The current implementation:
The implementation already supports registering global sets (not individual variables within them). When you create a class extending Working on fixing both Stache and Eloquent implementations to ensure they work consistently. |
Co-authored-by: tdwesten <[email protected]>
Co-authored-by: tdwesten <[email protected]>
|
@copilot Oke lets rethink the structure of globals as implement in the statamic builder. Here some info about the sets: Statamic Globals: GlobalSets and Globals — Relations Only
|
You're absolutely right about the distinction. The current implementation correctly registers GlobalSets (the containers/definitions) but not the Globals (the per-site data). Here's what we have now:
This matches how Collections work in the builder - we register the collection structure, but entries are added separately. The GlobalSet defines the container; blueprints define the fields; and the actual global data is managed through the CP or YAML files. Is this the intended design, or do you want to extend |
|
@copilot Oke, now create a way to test this working with a statamic laravel app with statamic builder addon installed |
…support' into copilot/add-global-registration-support
…`, refactor `BaseCollection`, and improve `MakeCollectionCommand` functionality Signed-off-by: Thomas van der Westen <[email protected]>
…repository enhancements, and related tests Signed-off-by: Thomas van der Westen <[email protected]>
…repository enhancements, and related tests Signed-off-by: Thomas van der Westen <[email protected]>
…ng `AssetContainerRepository`, `FieldsetRepository`, `TaxonomyRepository`, and custom field types like `ForeignField` and `Section` Signed-off-by: Thomas van der Westen <[email protected]>
…nd`, `MakeFieldsetCommand`, and `MakeTaxonomyCommand` Signed-off-by: Thomas van der Westen <[email protected]>
…es, commands, and related components Signed-off-by: Thomas van der Westen <[email protected]>
…sets, collections, taxonomies, globals, sites, and navigations; add relevant config options, methods, and tests Signed-off-by: Thomas van der Westen <[email protected]>
…iguration details Signed-off-by: Thomas van der Westen <[email protected]>
…Taggable`; add new field types including `Hidden`, `Money`, `Number`, `Password`, and `Rating` with respective tests Signed-off-by: Thomas van der Westen <[email protected]>
Signed-off-by: Thomas van der Westen <[email protected]>
…lementation, commands, discovery, and tests - Added `BaseAssetContainer` class with default methods for asset container management. - Created `MakeAssetContainerCommand` for generating asset container classes. - Enhanced auto-discovery to include asset containers. - Updated `AssetContainerRepository` to manage builder-registered containers. - Added configuration options and documentation for asset containers. - Included unit and feature tests for asset container functionality. Signed-off-by: Thomas van der Westen <[email protected]>
…aravel versions - Added `.github/workflows/tests.yml` with matrix strategy for PHP (8.2 - 8.4) and Laravel (10.* - 12.*). - Updated README badge to reflect the new workflow file. Signed-off-by: Thomas van der Westen <[email protected]>
- Added `: void` return type to all test closures for consistency and compatibility. - Removed unnecessary `TestCase` extends and extensions in test files. - Adjusted `uses` configuration in `Pest.php` to apply globally for all tests. Signed-off-by: Thomas van der Westen <[email protected]>
…c versions - Updated README with new PHP (8.2+), Laravel (11/12), and Statamic (5.4+/6.0 Alpha) requirements. - Modified `.github/workflows/tests.yml` to include Statamic matrix and stability settings. - Updated `composer.json` to reflect dependency range adjustments. - Updated `composer.lock` with dependency version changes. Signed-off-by: Thomas van der Westen <[email protected]>
- Removed `.github/workflows/ci.yml` to streamline workflows. - Merged linting and testing into a single `.github/workflows/tests.yml`. - Added dependency installation and dedicated linting job. - Adjusted test matrix for Laravel and Statamic versions. Signed-off-by: Thomas van der Westen <[email protected]>
- Removed `.github/workflows/ci.yml` to streamline workflows. - Merged linting and testing into a single `.github/workflows/tests.yml`. - Added dependency installation and dedicated linting job. - Adjusted test matrix for Laravel and Statamic versions. Signed-off-by: Thomas van der Westen <[email protected]>
Add support for registering globals with Eloquent and Stache Drivers ✅
Summary
This PR adds full support for registering global sets when using Statamic's Eloquent Driver AND fixes the default Stache driver implementation. Builder-registered global sets now properly show up in the Statamic control panel in both scenarios.
Implementation Details
Files Changed:
src/Repositories/EloquentGlobalRepository.php(new)Statamic\Eloquent\Globals\GlobalRepositoryconfig('statamic.builder.globals')src/ServiceProvider.php(modified)EloquentGlobalRepositorywhenstatamic.eloquent-driver.globals.driver === 'eloquent'GlobalRepositoryfor Stache-based storage (default)NavigationRepositorysrc/Stache/Stores/GlobalsStore.php(modified)$keyparameter from constructor callBaseTaxonomytoBaseGlobalSetBaseTaxonomyimporttests/Helpers/TestGlobalSet.php(new)tests/Unit/GlobalRepositoryTest.php(modified)How It Works
For Both Stache and Eloquent Drivers:
config('statamic.builder.globals')on repository initializationfind()andfindByHandle()methods check builder globals first, then database/filesStache Driver (default - file-based):
GlobalRepositoryusesGlobalsStoreto create GlobalSets via theregister()methodEloquent Driver (database-based):
EloquentGlobalRepositorymerges database globals with builder globalsUsage
Builder-registered global sets will now appear in:
GlobalSet::all()- Lists all global setsGlobalSet::findByHandle('site_settings')- Finds specific global setWhat's a Global Set?
In Statamic, a Global Set is a container that holds global variables. For example:
This PR enables you to register these global set containers via code, similar to how you register collections and taxonomies.
Plan Completed:
EloquentGlobalRepositoryclass for Eloquent DriverServiceProviderwith conditional bindingOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.