You are here

public function YamlFormTranslationManager::getConfigElements in YAML Form 8

Get form elements for specific language.

Parameters

\Drupal\yamlform\YamlFormInterface $yamlform: A form.

string $langcode: The language code for the form elements.

bool $reset: (optional) Whether to reset the translated config cache. Defaults to FALSE.

Return value

array A form's translated elements.

Overrides YamlFormTranslationManagerInterface::getConfigElements

2 calls to YamlFormTranslationManager::getConfigElements()
YamlFormTranslationManager::getBaseElements in src/YamlFormTranslationManager.php
Get base form elements from the site's default language.
YamlFormTranslationManager::getTranslationElements in src/YamlFormTranslationManager.php
Get flattened associative array of translated element properties.

File

src/YamlFormTranslationManager.php, line 56

Class

YamlFormTranslationManager
Defines a class to translate form elements.

Namespace

Drupal\yamlform

Code

public function getConfigElements(YamlFormInterface $yamlform, $langcode, $reset = FALSE) {

  // Note: Below code return the default languages elements for missing
  // translations.
  $config_override_language = $this->languageManager
    ->getConfigOverrideLanguage();
  $config_name = 'yamlform.yamlform.' . $yamlform
    ->id();

  // Reset cached config.
  if ($reset) {
    $this->configFactory
      ->reset($config_name);
  }
  $this->languageManager
    ->setConfigOverrideLanguage($this->languageManager
    ->getLanguage($langcode));
  $elements = $this->configFactory
    ->get($config_name)
    ->get('elements');
  $this->languageManager
    ->setConfigOverrideLanguage($config_override_language);
  return $elements ? Yaml::decode($elements) : [];
}