Skip to content
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

[5.x] Dictionaries #10380

Draft
wants to merge 32 commits into
base: 5.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2b8e531
Working prototype of dictionaries feature
duncanmcclean Jun 7, 2024
836b529
wip
duncanmcclean Jun 7, 2024
ee81cd2
Make it possible to search dictionaries
duncanmcclean Jun 20, 2024
2ea020a
wip
duncanmcclean Jun 20, 2024
0e3c63d
wip
duncanmcclean Jun 20, 2024
47136ee
tweaks
duncanmcclean Jun 21, 2024
5f49d48
wip
duncanmcclean Jun 21, 2024
923b804
Leave this return type open
duncanmcclean Jun 21, 2024
f969de2
Timezone dictionary
duncanmcclean Jun 21, 2024
4cc6bfe
tweaks to the fieldtype
duncanmcclean Jun 21, 2024
4ac1f23
wip
duncanmcclean Jun 21, 2024
19bb84d
Forms support
duncanmcclean Jun 21, 2024
8ae22f7
Allow adding config fields to dictionaries
duncanmcclean Jul 1, 2024
040912e
wip
duncanmcclean Jul 2, 2024
482bf42
wip
duncanmcclean Jul 2, 2024
082cec3
Add `make:dictionary` command
duncanmcclean Jul 2, 2024
6583ff8
Make these comments align with the comments in the stub
duncanmcclean Jul 2, 2024
ce4d3c7
simplify
duncanmcclean Jul 2, 2024
3578bf4
Add currencies dictionary
duncanmcclean Jul 2, 2024
aa24f33
Merge remote-tracking branch 'origin/5.x' into dictionaries
duncanmcclean Jul 2, 2024
0641a34
Undo changes by PHPStorm's refactoring feature
duncanmcclean Jul 2, 2024
0407218
Fix styling
duncanmcclean Jul 2, 2024
11e0fd2
wip
duncanmcclean Jul 2, 2024
aab430e
Merge branch 'dictionaries' of github.com:statamic/cms into dictionaries
duncanmcclean Jul 2, 2024
8059e04
remove unrelated change
duncanmcclean Jul 2, 2024
71601ed
dictionaries don't have scripts
duncanmcclean Jul 2, 2024
540e07a
rename variable in facade docblock
duncanmcclean Jul 2, 2024
f2aadc1
it's on my to-do list - remove the todo
duncanmcclean Jul 2, 2024
85a1452
Give the fieldtype a proper icon
duncanmcclean Jul 2, 2024
00a7701
wip
duncanmcclean Jul 2, 2024
a7f0ebd
Backfill tests
duncanmcclean Jul 2, 2024
52fe753
Fix styling
duncanmcclean Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/dictionaries/countries.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resources/dictionaries/currencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"code":"AED","name":"United Arab Emirates Dirham","symbol":"\u062f.\u0625.\u200f","decimal_digits":2},{"code":"AFN","name":"Afghan Afghani","symbol":"\u060b","decimal_digits":0},{"code":"ALL","name":"Albanian Lek","symbol":"Lek","decimal_digits":0},{"code":"AMD","name":"Armenian Dram","symbol":"\u0564\u0580.","decimal_digits":0},{"code":"ARS","name":"Argentine Peso","symbol":"$","decimal_digits":2},{"code":"AUD","name":"Australian Dollar","symbol":"$","decimal_digits":2},{"code":"AZN","name":"Azerbaijani Manat","symbol":"\u043c\u0430\u043d.","decimal_digits":2},{"code":"BAM","name":"Bosnia-Herzegovina Convertible Mark","symbol":"KM","decimal_digits":2},{"code":"BDT","name":"Bangladeshi Taka","symbol":"\u09f3","decimal_digits":2},{"code":"BGN","name":"Bulgarian Lev","symbol":"\u043b\u0432.","decimal_digits":2},{"code":"BHD","name":"Bahraini Dinar","symbol":"\u062f.\u0628.\u200f","decimal_digits":3},{"code":"BIF","name":"Burundian Franc","symbol":"FBu","decimal_digits":0},{"code":"BND","name":"Brunei Dollar","symbol":"$","decimal_digits":2},{"code":"BOB","name":"Bolivian Boliviano","symbol":"Bs","decimal_digits":2},{"code":"BRL","name":"Brazilian Real","symbol":"R$","decimal_digits":2},{"code":"BWP","name":"Botswanan Pula","symbol":"P","decimal_digits":2},{"code":"BYN","name":"Belarusian Ruble","symbol":"\u0440\u0443\u0431.","decimal_digits":2},{"code":"BZD","name":"Belize Dollar","symbol":"$","decimal_digits":2},{"code":"CAD","name":"Canadian Dollar","symbol":"$","decimal_digits":2},{"code":"CDF","name":"Congolese Franc","symbol":"FrCD","decimal_digits":2},{"code":"CHF","name":"Swiss Franc","symbol":"CHF","decimal_digits":2},{"code":"CLP","name":"Chilean Peso","symbol":"$","decimal_digits":0},{"code":"CNY","name":"Chinese Yuan","symbol":"CN\u00a5","decimal_digits":2},{"code":"COP","name":"Colombian Peso","symbol":"$","decimal_digits":0},{"code":"CRC","name":"Costa Rican Col\u00f3n","symbol":"\u20a1","decimal_digits":0},{"code":"CVE","name":"Cape Verdean Escudo","symbol":"CV$","decimal_digits":2},{"code":"CZK","name":"Czech Republic Koruna","symbol":"K\u010d","decimal_digits":2},{"code":"DJF","name":"Djiboutian Franc","symbol":"Fdj","decimal_digits":0},{"code":"DKK","name":"Danish Krone","symbol":"kr","decimal_digits":2},{"code":"DOP","name":"Dominican Peso","symbol":"RD$","decimal_digits":2},{"code":"DZD","name":"Algerian Dinar","symbol":"\u062f.\u062c.\u200f","decimal_digits":2},{"code":"EEK","name":"Estonian Kroon","symbol":"kr","decimal_digits":2},{"code":"EGP","name":"Egyptian Pound","symbol":"\u062c.\u0645.\u200f","decimal_digits":2},{"code":"ERN","name":"Eritrean Nakfa","symbol":"Nfk","decimal_digits":2},{"code":"ETB","name":"Ethiopian Birr","symbol":"Br","decimal_digits":2},{"code":"EUR","name":"Euro","symbol":"\u20ac","decimal_digits":2},{"code":"GBP","name":"British Pound Sterling","symbol":"\u00a3","decimal_digits":2},{"code":"GEL","name":"Georgian Lari","symbol":"GEL","decimal_digits":2},{"code":"GHS","name":"Ghanaian Cedi","symbol":"GH\u20b5","decimal_digits":2},{"code":"GNF","name":"Guinean Franc","symbol":"FG","decimal_digits":0},{"code":"GTQ","name":"Guatemalan Quetzal","symbol":"Q","decimal_digits":2},{"code":"HKD","name":"Hong Kong Dollar","symbol":"$","decimal_digits":2},{"code":"HNL","name":"Honduran Lempira","symbol":"L","decimal_digits":2},{"code":"HRK","name":"Croatian Kuna","symbol":"kn","decimal_digits":2},{"code":"HUF","name":"Hungarian Forint","symbol":"Ft","decimal_digits":0},{"code":"IDR","name":"Indonesian Rupiah","symbol":"Rp","decimal_digits":0},{"code":"ILS","name":"Israeli New Sheqel","symbol":"\u20aa","decimal_digits":2},{"code":"INR","name":"Indian Rupee","symbol":"\u099f\u0995\u09be","decimal_digits":2},{"code":"IQD","name":"Iraqi Dinar","symbol":"\u062f.\u0639.\u200f","decimal_digits":0},{"code":"IRR","name":"Iranian Rial","symbol":"\ufdfc","decimal_digits":0},{"code":"ISK","name":"Icelandic Kr\u00f3na","symbol":"kr","decimal_digits":0},{"code":"JMD","name":"Jamaican Dollar","symbol":"$","decimal_digits":2},{"code":"JOD","name":"Jordanian Dinar","symbol":"\u062f.\u0623.\u200f","decimal_digits":3},{"code":"JPY","name":"Japanese Yen","symbol":"\uffe5","decimal_digits":0},{"code":"KES","name":"Kenyan Shilling","symbol":"Ksh","decimal_digits":2},{"code":"KHR","name":"Cambodian Riel","symbol":"\u17db","decimal_digits":2},{"code":"KMF","name":"Comorian Franc","symbol":"FC","decimal_digits":0},{"code":"KRW","name":"South Korean Won","symbol":"\u20a9","decimal_digits":0},{"code":"KWD","name":"Kuwaiti Dinar","symbol":"\u062f.\u0643.\u200f","decimal_digits":3},{"code":"KZT","name":"Kazakhstani Tenge","symbol":"\u0442\u04a3\u0433.","decimal_digits":2},{"code":"LBP","name":"Lebanese Pound","symbol":"\u0644.\u0644.\u200f","decimal_digits":0},{"code":"LKR","name":"Sri Lankan Rupee","symbol":"SL Re","decimal_digits":2},{"code":"LTL","name":"Lithuanian Litas","symbol":"Lt","decimal_digits":2},{"code":"LVL","name":"Latvian Lats","symbol":"Ls","decimal_digits":2},{"code":"LYD","name":"Libyan Dinar","symbol":"\u062f.\u0644.\u200f","decimal_digits":3},{"code":"MAD","name":"Moroccan Dirham","symbol":"\u062f.\u0645.\u200f","decimal_digits":2},{"code":"MDL","name":"Moldovan Leu","symbol":"MDL","decimal_digits":2},{"code":"MGA","name":"Malagasy Ariary","symbol":"MGA","decimal_digits":0},{"code":"MKD","name":"Macedonian Denar","symbol":"MKD","decimal_digits":2},{"code":"MMK","name":"Myanma Kyat","symbol":"K","decimal_digits":0},{"code":"MOP","name":"Macanese Pataca","symbol":"MOP$","decimal_digits":2},{"code":"MUR","name":"Mauritian Rupee","symbol":"MURs","decimal_digits":0},{"code":"MXN","name":"Mexican Peso","symbol":"$","decimal_digits":2},{"code":"MYR","name":"Malaysian Ringgit","symbol":"RM","decimal_digits":2},{"code":"MZN","name":"Mozambican Metical","symbol":"MTn","decimal_digits":2},{"code":"NAD","name":"Namibian Dollar","symbol":"N$","decimal_digits":2},{"code":"NGN","name":"Nigerian Naira","symbol":"\u20a6","decimal_digits":2},{"code":"NIO","name":"Nicaraguan C\u00f3rdoba","symbol":"C$","decimal_digits":2},{"code":"NOK","name":"Norwegian Krone","symbol":"kr","decimal_digits":2},{"code":"NPR","name":"Nepalese Rupee","symbol":"\u0928\u0947\u0930\u0942","decimal_digits":2},{"code":"NZD","name":"New Zealand Dollar","symbol":"$","decimal_digits":2},{"code":"OMR","name":"Omani Rial","symbol":"\u0631.\u0639.\u200f","decimal_digits":3},{"code":"PAB","name":"Panamanian Balboa","symbol":"B\/.","decimal_digits":2},{"code":"PEN","name":"Peruvian Nuevo Sol","symbol":"S\/.","decimal_digits":2},{"code":"PHP","name":"Philippine Peso","symbol":"\u20b1","decimal_digits":2},{"code":"PKR","name":"Pakistani Rupee","symbol":"\u20a8","decimal_digits":0},{"code":"PLN","name":"Polish Zloty","symbol":"z\u0142","decimal_digits":2},{"code":"PYG","name":"Paraguayan Guarani","symbol":"\u20b2","decimal_digits":0},{"code":"QAR","name":"Qatari Rial","symbol":"\u0631.\u0642.\u200f","decimal_digits":2},{"code":"RON","name":"Romanian Leu","symbol":"RON","decimal_digits":2},{"code":"RSD","name":"Serbian Dinar","symbol":"\u0434\u0438\u043d.","decimal_digits":0},{"code":"RUB","name":"Russian Ruble","symbol":"\u20bd.","decimal_digits":2},{"code":"RWF","name":"Rwandan Franc","symbol":"FR","decimal_digits":0},{"code":"SAR","name":"Saudi Riyal","symbol":"\u0631.\u0633.\u200f","decimal_digits":2},{"code":"SDG","name":"Sudanese Pound","symbol":"SDG","decimal_digits":2},{"code":"SEK","name":"Swedish Krona","symbol":"kr","decimal_digits":2},{"code":"SGD","name":"Singapore Dollar","symbol":"$","decimal_digits":2},{"code":"SOS","name":"Somali Shilling","symbol":"Ssh","decimal_digits":0},{"code":"SYP","name":"Syrian Pound","symbol":"\u0644.\u0633.\u200f","decimal_digits":0},{"code":"THB","name":"Thai Baht","symbol":"\u0e3f","decimal_digits":2},{"code":"TND","name":"Tunisian Dinar","symbol":"\u062f.\u062a.\u200f","decimal_digits":3},{"code":"TOP","name":"Tongan Pa\u02bbanga","symbol":"T$","decimal_digits":2},{"code":"TRY","name":"Turkish Lira","symbol":"TL","decimal_digits":2},{"code":"TTD","name":"Trinidad and Tobago Dollar","symbol":"$","decimal_digits":2},{"code":"TWD","name":"New Taiwan Dollar","symbol":"NT$","decimal_digits":2},{"code":"TZS","name":"Tanzanian Shilling","symbol":"TSh","decimal_digits":0},{"code":"UAH","name":"Ukrainian Hryvnia","symbol":"\u20b4","decimal_digits":2},{"code":"UGX","name":"Ugandan Shilling","symbol":"USh","decimal_digits":0},{"code":"USD","name":"US Dollar","symbol":"$","decimal_digits":2},{"code":"UYU","name":"Uruguayan Peso","symbol":"$","decimal_digits":2},{"code":"UZS","name":"Uzbekistan Som","symbol":"UZS","decimal_digits":0},{"code":"VEF","name":"Venezuelan Bol\u00edvar","symbol":"Bs.F.","decimal_digits":2},{"code":"VND","name":"Vietnamese Dong","symbol":"\u20ab","decimal_digits":0},{"code":"XAF","name":"CFA Franc BEAC","symbol":"FCFA","decimal_digits":0},{"code":"XOF","name":"CFA Franc BCEAO","symbol":"CFA","decimal_digits":0},{"code":"YER","name":"Yemeni Rial","symbol":"\u0631.\u064a.\u200f","decimal_digits":0},{"code":"ZAR","name":"South African Rand","symbol":"R","decimal_digits":2},{"code":"ZMK","name":"Zambian Kwacha","symbol":"ZK","decimal_digits":0},{"code":"ZWL","name":"Zimbabwean Dollar","symbol":"ZWL$","decimal_digits":0}]
4 changes: 4 additions & 0 deletions resources/js/bootstrap/fieldtypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import Routes from '../components/collections/Routes.vue';
import TitleFormats from '../components/collections/TitleFormats.vue';
import ColorFieldtype from '../components/fieldtypes/ColorFieldtype.vue';
import DateFieldtype from '../components/fieldtypes/DateFieldtype.vue';
import DictionaryFieldtype from "../components/fieldtypes/DictionaryFieldtype.vue";
import DictionaryFields from "../components/fieldtypes/DictionaryFields.vue";
import FieldDisplayFieldtype from '../components/fieldtypes/FieldDisplayFieldtype.vue';
import FieldsFieldtype from '../components/fieldtypes/grid/FieldsFieldtype.vue';
import FilesFieldtype from '../components/fieldtypes/FilesFieldtype.vue';
Expand Down Expand Up @@ -85,6 +87,8 @@ Vue.component('collection_routes-fieldtype', Routes);
Vue.component('collection_title_formats-fieldtype', TitleFormats);
Vue.component('color-fieldtype', ColorFieldtype);
Vue.component('date-fieldtype', DateFieldtype);
Vue.component('dictionary-fieldtype', DictionaryFieldtype);
Vue.component('dictionary_fields-fieldtype', DictionaryFields);
Vue.component('field_display-fieldtype', FieldDisplayFieldtype);
Vue.component('fields-fieldtype', FieldsFieldtype);
Vue.component('files-fieldtype', FilesFieldtype);
Expand Down
105 changes: 105 additions & 0 deletions resources/js/components/fieldtypes/DictionaryFields.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<publish-container
name="dictionary-fields"
:blueprint="blueprint"
:values="value"
:meta="publishMeta"
:is-config="true"
:errors="errors"
@updated="update"
>
<publish-fields
slot-scope="{ setFieldValue, setFieldMeta }"
:fields="fields"
@updated="setFieldValue"
@meta-updated="setFieldMeta"
/>
</publish-container>
</template>

<script>
import Fieldtype from "./Fieldtype.vue";

export default {
mixins: [Fieldtype],

inject: ['storeName'],

computed: {
dictionary() {
return this.value?.type;
},

fields() {
return this.meta.type.fields.concat(this.meta.dictionaries[this.dictionary]?.fields || [])
},

blueprint() {
return {
tabs: [{
fields: this.fields
}]
}
},

publishMeta() {
return {
...this.meta.type.meta,
...this.meta.dictionaries[this.dictionary]?.meta
}
},

errors() {
const state = this.$store.state.publish[this.storeName];

if (! state) {
return {};
}

let errors = {}

// Filter errors to only include those for this field, and remove the field path prefix
// if there is one, then append it to the errors object.
Object.entries(state.errors)
.filter(([key, value]) => key.startsWith(this.fieldPathPrefix || this.handle))
.forEach(([key, value]) => {
errors[key.split('.').pop()] = value
})

return errors
},
},

watch: {
dictionary() {
this.update({
type: dictionary,
...this.meta.dictionaries[this.dictionary]?.defaults
})
},
},
}
</script>

<style>
.dictionary_fields-fieldtype {
@apply p-0;

.publish-fields {
@apply w-full;
}

.config-field {
@apply md:flex flex-wrap border-b border-gray-400 dark:border-dark-900 w-full;
@apply p-3 @sm:p-4 m-0;

.field-inner {
@apply w-full md:w-1/2 rtl:md:pl-8 ltr:md:pr-8;
}

.field-inner + div {
@apply w-full md:w-1/2;
}
}
}
</style>
Loading
Loading