2

I'm attempting to get the allowed_values of a non-translatable list_string field. The allowed_values of this field are translated though and we want to get those allowed_values into a specific language & not the current UI one.

Here is my draft attempt:

// Override language before loading field configuration.
$this->languageManager->setConfigOverrideLanguage($this->languageManager->getLanguage('fr'));

// Load the field configuration in the language forced before. 
$field_info = $this->fieldConfigStorage->load('profile.customer.field_title');
$label = $field_info->getLabel();
$allowed_values = $field_info->getSetting('allowed_values');

// Dump values for debugging.
dump($label);
dump($field_info);
dump($allowed_values);

With my current code, I get the proper forced label (here fr) but when I use the ::getSetting('allowed_values') I receive the allowed_values in the current UI language instead of forced one.

Does any one have any idea ? Many thanks.

Kevin Wenger
  • 1,484
  • 1
  • 13
  • 29
  • Do you rely on config-translation module from core (or which one) ? How are defined *allowed_values* for that field ? – EricLavault May 31 '19 at 07:16
  • Hello Eric, Yes indeed, we use the Core implementation of List Text Field & we use the standard configuration translation feature, you can see an example here: https://drupal.stackexchange.com/questions/233320/translate-the-allowed-values-list-of-an-entity-access-field Allowed values are defined in the field configuration (and translation also) as they should be. – Kevin Wenger Jun 04 '19 at 08:07

0 Answers0