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

Add translationMode option to MLRepeater & MLNestedForm formwidgets #76

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8b0ee0a
first draft of MLRepeaterFields
mjauvin Feb 19, 2024
faef2c3
merge new repeater field with internal fields translation
mjauvin Feb 19, 2024
2e30b7e
put all elements into the array then implode
mjauvin Feb 20, 2024
0ccb6c4
cleanup
mjauvin Feb 20, 2024
203c991
allow field translatable config for repeater forms in "fields" transl…
mjauvin Feb 20, 2024
685fa43
properly store repeater fields translations in attributes table
mjauvin Feb 22, 2024
1f73b76
save a call by determining if the field parent is jsonable
mjauvin Feb 22, 2024
a8724e5
simplify code
mjauvin Feb 22, 2024
f0da1c5
improve code robustness and add some comments
mjauvin Feb 22, 2024
ef184a3
remove translatable config support
mjauvin Feb 22, 2024
0b7d1bf
cleanup
mjauvin Feb 22, 2024
d942348
add docstring param & remove old code
mjauvin Feb 22, 2024
dddeef9
simplify code
mjauvin Feb 22, 2024
462b432
add example of translationMode: fields in README
mjauvin Feb 22, 2024
495726f
improve yaml syntax
mjauvin Feb 22, 2024
0c83533
improve readme syntax
mjauvin Feb 22, 2024
634e6ee
more readme syntax improvements
mjauvin Feb 22, 2024
579a9eb
improve translationMode section in readme
mjauvin Feb 22, 2024
e6a8df8
add repeater translatable fields from themedata; fix issue
mjauvin Feb 22, 2024
edbe849
properly merge values
mjauvin Feb 22, 2024
36353b0
value might be null
mjauvin Feb 22, 2024
0bed2fc
improve code readability
mjauvin Feb 22, 2024
533285a
no need to hardcode model name here
mjauvin Feb 22, 2024
1813c85
fix for groups mode
mjauvin Feb 23, 2024
681cafa
account for nestedform field types in repeater
mjauvin Feb 23, 2024
e9e9c03
make sure arrays are provided to array_replace_recursive()
mjauvin Feb 24, 2024
533d964
fix repeater in regular translation mode
mjauvin Feb 24, 2024
d6ec621
also apply to nestedform
mjauvin Feb 24, 2024
a7859ed
fix widget name
mjauvin Feb 24, 2024
e2fb60b
add nestedform to README example
mjauvin Feb 25, 2024
6047f8c
add top-level array to translatable
mjauvin Feb 25, 2024
f98357e
Update Plugin.php
LukeTowers Feb 26, 2024
c4d55bc
alternative to using @
mjauvin Feb 27, 2024
aacb3d0
fix reordering issues
mjauvin Feb 27, 2024
700c28c
do not call with empty fields
mjauvin Feb 27, 2024
6aef498
make sure we have an array
mjauvin Feb 29, 2024
c074a60
prefix plugin name to dynamic method
mjauvin Feb 29, 2024
07c0a06
rename last instance
mjauvin Mar 5, 2024
51bcdaf
purge translations for deleted repeaters
mjauvin Mar 5, 2024
5c6bf36
Merge branch 'main' into wip-ml-repeater-fields
mjauvin Mar 18, 2024
8b7f203
Merge branch 'main' into wip-ml-repeater-fields
mjauvin Mar 18, 2024
7bb6a86
remove code duplication
mjauvin Mar 19, 2024
d617cbc
fix method visibility and add doc string
mjauvin Mar 19, 2024
e23bb1d
fix extension
mjauvin Mar 27, 2024
cc3aeef
add option to specify translatable fields in fields.yaml
mjauvin Mar 27, 2024
0720e1d
fix method name clash
mjauvin Mar 27, 2024
6ee2a55
auto-add jsonable fields used by repeater/nested to translatable array
mjauvin Mar 27, 2024
9d2fa6d
no need to add dynamic property
mjauvin Mar 27, 2024
fce0cce
document the new translatable field config
mjauvin Mar 27, 2024
f7996c4
build config for all cases
mjauvin Apr 2, 2024
1bcf104
add css fix for nestedforms
mjauvin Apr 4, 2024
1f67fcf
Fix getLocaleFieldName behavior with empty formField arrayName (#83)
nmiyazaki-chapleau May 29, 2024
0e12827
Fix issue with loading translated data with arrayNames
nmiyazaki-chapleau Aug 1, 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
14 changes: 11 additions & 3 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,17 @@ protected function extendCmsModule(): void
ThemeData::extend(function ($model) {
$model->bindEvent('model.afterFetch', function() use ($model) {
$translatable = [];
foreach ($model->getFormFields() as $id => $field) {
if (!empty($field['translatable'])) {
$translatable[] = $id;
foreach ($model->getFormFields() as $fieldName => $fieldConfig) {
if (array_get($fieldConfig, 'translatable', false)) {
$translatable[] = $fieldName;
}
$type = array_get($fieldConfig, 'type', 'text');
if (in_array($type, ['repeater', 'nestedform'])) {
foreach (array_get($fieldConfig, 'form.fields', []) as $subFieldName => $subFieldConfig) {
if (array_get($subFieldConfig, 'translatable', false)) {
$translatable[] = sprintf("%s[%s]", $fieldName, $subFieldName);
}
}
}
}
$this->extendModel($model, 'model', $translatable);
Expand Down
Loading