Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function setConfig(Config $base_config, LanguageConfigOverride $config_translation, $config_values, $base_key = NULL)
 {
     foreach ($this->element as $key => $element) {
         $element_key = isset($base_key) ? "{$base_key}.{$key}" : $key;
         if ($form_element = ConfigTranslationFormBase::createFormElement($element)) {
             // Traverse into the next level of the configuration.
             $value = isset($config_values[$key]) ? $config_values[$key] : NULL;
             $form_element->setConfig($base_config, $config_translation, $value, $element_key);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     drupal_set_message($this->t('Successfully saved @language translation.', array('@language' => $this->language->name)));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function saveTranslation(JobItemInterface $job_item, $target_langcode)
 {
     try {
         $config_mapper = $this->getMapper($job_item);
     } catch (TMGMTException $e) {
         $job_item->addMessage('The entity %id of type %type does not exist, the job can not be completed.', array('%id' => $job_item->getItemId(), '%type' => $job_item->getItemType()), 'error');
         return FALSE;
     }
     $data = $job_item->getData();
     $config_names = $config_mapper->getConfigNames();
     // We need to refactor the array just as we did in getData.
     if (count($config_names) == 1) {
         $data[$config_names[0]] = $data;
     } else {
         // Replace the arrays keys back.
         foreach ($data as $key => $value) {
             $new_key = str_replace('__', '.', $key);
             $data[$new_key] = $value;
             unset($data[$key]);
         }
     }
     foreach ($config_mapper->getConfigNames() as $name) {
         $schema = $this->typedConfig->get($name);
         // Set configuration values based on form submission and source values.
         $base_config = $this->configFactoryManager->getEditable($name);
         $config_translation = $this->languageManager->getLanguageConfigOverride($target_langcode, $name);
         $element = ConfigTranslationFormBase::createFormElement($schema);
         $element->setConfig($base_config, $config_translation, $this->convertToTranslation($data[$name]));
         // If no overrides, delete language specific configuration file.
         $saved_config = $config_translation->get();
         if (empty($saved_config)) {
             $config_translation->delete();
         } else {
             $config_translation->save();
         }
     }
     return TRUE;
 }