diff --git a/config/assets.php b/config/assets.php index 2618b48e33b..ca762434986 100644 --- a/config/assets.php +++ b/config/assets.php @@ -101,6 +101,19 @@ ], + /* + |-------------------------------------------------------------------------- + | Default Container + |-------------------------------------------------------------------------- + | + | When adding Assets fields to blueprints, Statamic will use this container + | as the default. You can override this setting on a field-by-field basis. + | Changing this value may break existing asset relationships. + | + */ + + 'default_container' => 'assets', + /* |-------------------------------------------------------------------------- | Auto-Crop Assets diff --git a/src/Fieldtypes/AssetContainer.php b/src/Fieldtypes/AssetContainer.php index b8ebddaaa10..c5977ce23fc 100644 --- a/src/Fieldtypes/AssetContainer.php +++ b/src/Fieldtypes/AssetContainer.php @@ -37,4 +37,9 @@ public function augmentValue($value) { return Facades\AssetContainer::find($value); } + + public function defaultValue() + { + return config('statamic.assets.default_container'); + } } diff --git a/src/Fieldtypes/Assets/Assets.php b/src/Fieldtypes/Assets/Assets.php index d60546b7bda..72ffbb7e128 100644 --- a/src/Fieldtypes/Assets/Assets.php +++ b/src/Fieldtypes/Assets/Assets.php @@ -41,7 +41,6 @@ protected function configFieldItems(): array 'max_items' => 1, 'mode' => 'select', 'required' => true, - 'default' => AssetContainer::all()->count() == 1 ? AssetContainer::all()->first()->handle() : null, 'force_in_config' => true, 'width' => '50', ], diff --git a/tests/Auth/HasAvatarTest.php b/tests/Auth/HasAvatarTest.php index c743360eda3..06267261d0e 100644 --- a/tests/Auth/HasAvatarTest.php +++ b/tests/Auth/HasAvatarTest.php @@ -27,7 +27,7 @@ public function setUp(): void private function withAvatarField() { - $blueprint = Blueprint::makeFromFields(['avatar' => ['type' => 'assets', 'max_files' => 1]]); + $blueprint = Blueprint::makeFromFields(['avatar' => ['type' => 'assets', 'max_files' => 1, 'container' => 'avatars']]); BlueprintRepository::shouldReceive('find')->with('user')->andReturn($blueprint); diff --git a/tests/Fieldtypes/AssetsTest.php b/tests/Fieldtypes/AssetsTest.php index 19ae89d96d0..c2b0b734759 100644 --- a/tests/Fieldtypes/AssetsTest.php +++ b/tests/Fieldtypes/AssetsTest.php @@ -222,6 +222,7 @@ public function fieldtype($config = []) { return (new Assets)->setField(new Field('test', array_merge([ 'type' => 'assets', + 'container' => 'test', ], $config))); }