Skip to content

Commit

Permalink
[5.x] Add "Container" option to Asset Folders fieldtype (#11099)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Nov 11, 2024
1 parent 1d78ccf commit 09a2c4b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
6 changes: 2 additions & 4 deletions resources/js/components/fieldtypes/AssetFolderFieldtype.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<template>
<div class="asset-folder-fieldtype-wrapper">
<small class="help-block text-gray-600" v-if="!container">{{ __('Select asset container') }}</small>

<relationship-fieldtype
v-if="container"
:handle="handle"
:value="value"
:meta="relationshipMeta"
:config="{ type: 'asset_folder' }"
:config="{ type: 'asset_folder', max_items: this.config.max_items }"
@input="update"
/>
</div>
Expand All @@ -23,7 +21,7 @@ export default {
computed: {
container() {
return data_get(this.$store.state.publish[this.storeName].values.container, '0', null);
return data_get(this.$store.state.publish[this.storeName].values.container, '0', this.config.container);
},
relationshipMeta() {
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'assets.dynamic_folder_pending_field' => 'This field will be available once :field is set.',
'assets.dynamic_folder_pending_save' => 'This field will be available after saving.',
'assets.title' => 'Assets',
'asset_folders.config.container' => 'Choose which asset container to use for this field.',
'bard.config.allow_source' => 'Enable to view the HTML source code while writing.',
'bard.config.always_show_set_button' => 'Enable to always show the "Add Set" button.',
'bard.config.buttons' => 'Choose which buttons to show in the toolbar.',
Expand Down
34 changes: 34 additions & 0 deletions src/Fieldtypes/AssetFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,40 @@ class AssetFolder extends Relationship
protected $canCreate = false;
protected $selectable = false;

protected function configFieldItems(): array
{
return [
[
'display' => __('Appearance & Behavior'),
'fields' => [
'max_items' => [
'display' => __('Max Items'),
'instructions' => __('statamic::messages.max_items_instructions'),
'min' => 1,
'type' => 'integer',
],
'mode' => [
'display' => __('UI Mode'),
'instructions' => __('statamic::fieldtypes.relationship.config.mode'),
'type' => 'radio',
'default' => 'default',
'options' => [
'default' => __('Stack Selector'),
'select' => __('Select Dropdown'),
'typeahead' => __('Typeahead Field'),
],
],
'container' => [
'display' => __('Container'),
'instructions' => __('statamic::fieldtypes.asset_folders.config.container'),
'type' => 'asset_container',
'max_items' => 1,
],
],
],
];
}

protected function toItemArray($id, $site = null)
{
return ['title' => $id, 'id' => $id];
Expand Down

0 comments on commit 09a2c4b

Please sign in to comment.