public function updateCMSFields(FieldList $fields)
{
// get all fields to translate and remove
$translated = $this->getTranslatedTables();
foreach ($translated as $table => $translatedFields) {
foreach ($translatedFields as $translatedField) {
// Find field matching this translated field
// If the translated field has an ID suffix also check for the non-suffixed version
// E.g. UploadField()
$field = $fields->dataFieldByName($translatedField);
if (!$field && preg_match('/^(?<field>\\w+)ID$/', $translatedField, $matches)) {
$field = $fields->dataFieldByName($matches['field']);
}
// Highlight any translatable field
if ($field && !$field->hasClass('LocalisedField')) {
// Add a language indicator next to the fluent icon
$locale = Fluent::current_locale();
$title = $field->Title();
$titleClasses = 'fluent-locale-label';
// Add a visual indicator for whether the value has been changed from the default locale
$isModified = Fluent::isFieldModified($this->owner, $field, $locale);
$modifiedTitle = 'Using default locale value';
if ($isModified) {
$titleClasses .= ' fluent-modified-value';
$modifiedTitle = 'Modified from default locale value - click to reset';
}
$field->setTitle(sprintf('<span class="%s" title="%s">%s</span>%s', $titleClasses, $modifiedTitle, strtok($locale, '_'), $title));
// Set the default value to the element so we can compare it with JavaScript
if (Fluent::default_locale() !== $locale) {
$field->setAttribute('data-default-locale-value', $this->owner->{Fluent::db_field_for_locale($field->getName(), Fluent::default_locale())});
}
$field->addExtraClass('LocalisedField');
}
// Remove translation DBField from automatic scaffolded fields
foreach (Fluent::locales() as $locale) {
$fieldName = Fluent::db_field_for_locale($translatedField, $locale);
$fields->removeByName($fieldName, true);
}
}
}
$this->addLocaleIndicatorMessage($fields);
}