By default StoryChief will publish to your default collection, using the default blueprint and the mapping defined in config/storychief.php
.
The following article explains how to setup publishing to multiple collection types / blueprints and mapping.
Step 1: Create a custom field of type "single option" on StoryChief where you can select your collection type.
Add options and set a label and description making it clear for your case.
See the example below.
Step 2: Configure your Statamic website to change collection, blueprint and/or mapping based on the custom field value we created in step 1.
β The following should be done by your developer.
Inside App\Providers\AppServiceProvider.php
register a custom implementation for the storychief_config
facade.
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// Register a new binding for the facade
app()->bind('storychief_config', function () {
return new \App\Facades\CustomStoryChiefConfig();
});
}
...
Create the CustomStoryChiefConfig()
class where you can change the collection, blueprint and mapping based on the incoming $payload
.
<?php namespace App\Facades;
use Statamic\Support\Arr;
use StoryChief\StoryChief\Helpers\Configuration as StoryChiefConfig;
class CustomStoryChiefConfig extends StoryChiefConfig
{
public function set(array $payload): void
{
// Find the custom field in the $payload
$collectionCustomField = Arr::first(
$payload['data']['custom_fields'] ?? [],
function($field){
return (isset($field['key']) && $field['key'] === 'MY_CUSTOM_FIELD_KEY');
}
);
if(
$collectionCustomField &&
$collectionCustomField['value'] === 'news'
){
config()->set('storychief.collection', 'news');
config()->set('storychief.blueprint', 'newsitem');
config()->set('storychief.mapping', [
'title' => 'title',
'content' => 'body',
]);
}
}
}
All done π