Skip to content

Commit

Permalink
allow field translatable config for repeater forms in "fields" transl…
Browse files Browse the repository at this point in the history
…ationMode
  • Loading branch information
mjauvin committed Feb 20, 2024
1 parent 0ccb6c4 commit 203c991
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions classes/EventRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public function registerModelTranslation($widget)
}

if ($widget->isNested) {
$widget->fields = $this->processFormMLFields($widget->fields, $model, $this->getWidgetName($widget));
if (isset($widget->config->translationMode) && $widget->config->translationMode === 'fields') {
$widget->fields = $this->processFormMLFields($widget->fields, $model, $this->getWidgetName($widget));
}
return;
}

Expand Down Expand Up @@ -198,10 +200,13 @@ protected function processFormMLFields($fields, $model, $parent = null)
// apply to fields with any context
list($fieldName, $context) = explode('@', $name);
}
if (!array_key_exists($fieldName, $translatable)) {
if (! (array_get($config, 'translatable') || array_key_exists($fieldName, $translatable)) ) {
// field is not in model's translatable array and its translatable config is false
continue;
}

// field is in model's translatable array or its translatable config is true

$type = array_get($config, 'type', 'text');
if (array_key_exists($type, $typesMap)) {
$fields[$name]['type'] = $typesMap[$type];
Expand Down
6 changes: 4 additions & 2 deletions formwidgets/MLRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ class MLRepeater extends Repeater
*/
public function init()
{
$this->fillFromConfig(['translationMode']);
// make the translationMode available to the repeater items formwidgets
$this->config->form['translationMode'] = $this->translationMode;

parent::init();
$this->initLocale();

$this->fillFromConfig(['translationMode']);

if ($this->translationMode === 'fields' && $this->model) {
$this->model->extend(function () {
$this->addDynamicMethod('getJsonAttributeTranslated', function ($key, $locale) {
Expand Down

0 comments on commit 203c991

Please sign in to comment.