Skip to content

Commit

Permalink
Allow non-CP collection config fields to persist (#381)
Browse files Browse the repository at this point in the history
* Allow non-CP collection config fields to persist

* Taxonomies too

* And the rest

* handle null
  • Loading branch information
ryanmitchell authored Nov 19, 2024
1 parent 4440a8b commit f2ad2f1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 50 deletions.
24 changes: 13 additions & 11 deletions src/Assets/AssetContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ public static function makeModelFromContract(AssetContainerContract $source)
$model = app('statamic.eloquent.assets.container_model')::firstOrNew(['handle' => $source->handle()])->fill([
'title' => $source->title(),
'disk' => $source->diskHandle() ?? config('filesystems.default'),
'settings' => [
'allow_uploads' => $source->allowUploads(),
'allow_downloading' => $source->allowDownloading(),
'allow_moving' => $source->allowMoving(),
'allow_renaming' => $source->allowRenaming(),
'create_folders' => $source->createFolders(),
'search_index' => $source->searchIndex(),
'source_preset' => $source->sourcePreset,
'warm_presets' => $source->warmPresets,
'validation_rules' => $source->validationRules(),
],
'settings' => [],
]);

$model->settings = array_merge($model->settings ?? [], [
'allow_uploads' => $source->allowUploads(),
'allow_downloading' => $source->allowDownloading(),
'allow_moving' => $source->allowMoving(),
'allow_renaming' => $source->allowRenaming(),
'create_folders' => $source->createFolders(),
'search_index' => $source->searchIndex(),
'source_preset' => $source->sourcePreset,
'warm_presets' => $source->warmPresets,
'validation_rules' => $source->validationRules(),
]);

// Set initial timestamps.
Expand Down
52 changes: 28 additions & 24 deletions src/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,36 @@ public static function makeModelFromContract(Contract $source)
{
$class = app('statamic.eloquent.collections.model');

return $class::firstOrNew(['handle' => $source->handle])->fill([
$model = $class::firstOrNew(['handle' => $source->handle])->fill([
'title' => $source->title ?? $source->handle,
'settings' => [
'routes' => $source->routes,
'slugs' => $source->requiresSlugs(),
'title_formats' => collect($source->titleFormats())->filter(),
'mount' => $source->mount,
'dated' => $source->dated,
'sites' => $source->sites,
'template' => $source->template,
'layout' => $source->layout,
'inject' => $source->cascade,
'search_index' => $source->searchIndex,
'revisions' => $source->revisionsEnabled(),
'default_status' => $source->defaultPublishState,
'structure' => $source->structureContents(),
'sort_dir' => $source->customSortDirection(),
'sort_field' => $source->customSortField(),
'taxonomies' => $source->taxonomies,
'propagate' => $source->propagate(),
'past_date_behavior' => $source->pastDateBehavior(),
'future_date_behavior' => $source->futureDateBehavior(),
'preview_targets' => $source->previewTargets(),
'origin_behavior' => $source->originBehavior(),
],
'settings' => [],
]);

$model->settings = array_merge($model->settings ?? [], [
'routes' => $source->routes,
'slugs' => $source->requiresSlugs(),
'title_formats' => collect($source->titleFormats())->filter(),
'mount' => $source->mount,
'dated' => $source->dated,
'sites' => $source->sites,
'template' => $source->template,
'layout' => $source->layout,
'inject' => $source->cascade,
'search_index' => $source->searchIndex,
'revisions' => $source->revisionsEnabled(),
'default_status' => $source->defaultPublishState,
'structure' => $source->structureContents(),
'sort_dir' => $source->customSortDirection(),
'sort_field' => $source->customSortField(),
'taxonomies' => $source->taxonomies,
'propagate' => $source->propagate(),
'past_date_behavior' => $source->pastDateBehavior(),
'future_date_behavior' => $source->futureDateBehavior(),
'preview_targets' => $source->previewTargets(),
'origin_behavior' => $source->originBehavior(),
]);

return $model;
}

public function model($model = null)
Expand Down
18 changes: 11 additions & 7 deletions src/Structures/Nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ public static function makeModelFromContract(Contract $source)
{
$class = app('statamic.eloquent.navigations.model');

return $class::firstOrNew(['handle' => $source->handle()])->fill([
$model = $class::firstOrNew(['handle' => $source->handle()])->fill([
'title' => $source->title(),
'settings' => [
'collections' => $source->collections()->map->handle(),
'select_across_sites' => $source->canSelectAcrossSites(),
'max_depth' => $source->maxDepth(),
'expects_root' => $source->expectsRoot(),
],
'settings' => [],
]);

$model->settings = array_merge($model->settings ?? [], [
'collections' => $source->collections()->map->handle(),
'select_across_sites' => $source->canSelectAcrossSites(),
'max_depth' => $source->maxDepth(),
'expects_root' => $source->expectsRoot(),
]);

return $model;
}

public function model($model = null)
Expand Down
20 changes: 12 additions & 8 deletions src/Taxonomies/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ public static function makeModelFromContract(Contract $source)
{
$class = app('statamic.eloquent.taxonomies.model');

return $class::firstOrNew(['handle' => $source->handle()])->fill([
$model = $class::firstOrNew(['handle' => $source->handle()])->fill([
'title' => $source->title(),
'sites' => $source->sites(),
'settings' => [
'revisions' => $source->revisionsEnabled(),
'preview_targets' => $source->previewTargets(),
'term_template' => $source->hasCustomTermTemplate() ? $source->termTemplate() : null,
'template' => $source->hasCustomTemplate() ? $source->template() : null,
'layout' => $source->layout,
],
'settings' => [],
]);

$model->settings = array_merge($model->settings ?? [], [
'revisions' => $source->revisionsEnabled(),
'preview_targets' => $source->previewTargets(),
'term_template' => $source->hasCustomTermTemplate() ? $source->termTemplate() : null,
'template' => $source->hasCustomTemplate() ? $source->template() : null,
'layout' => $source->layout,
]);

return $model;
}

public function model($model = null)
Expand Down

0 comments on commit f2ad2f1

Please sign in to comment.