コード例 #1
0
ファイル: LocaleSettingsForm.php プロジェクト: shumer/blog
 /**
  * Implements \Drupal\Core\Form\FormInterface::submitForm().
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $values = $form_state['values'];
     $config = $this->config('locale.settings');
     $config->set('translation.update_interval_days', $values['update_interval_days'])->save();
     $config->set('translation.use_source', $values['use_source'])->save();
     switch ($values['overwrite']) {
         case LOCALE_TRANSLATION_OVERWRITE_ALL:
             $config->set('translation.overwrite_customized', TRUE)->set('translation.overwrite_not_customized', TRUE)->save();
             break;
         case LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED:
             $config->set('translation.overwrite_customized', FALSE)->set('translation.overwrite_not_customized', TRUE)->save();
             break;
         case LOCALE_TRANSLATION_OVERWRITE_NONE:
             $config->set('translation.overwrite_customized', FALSE)->set('translation.overwrite_not_customized', FALSE)->save();
             break;
     }
     // Invalidate the cached translation status when the configuration setting
     // of 'use_source' changes.
     if ($form['use_source']['#default_value'] != $form_state['values']['use_source']) {
         locale_translation_clear_status();
     }
     parent::submitForm($form, $form_state);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->moduleHandler->loadInclude('locale', 'fetch.inc');
     $this->moduleHandler->loadInclude('locale', 'bulk.inc');
     $langcodes = array_filter($form_state->getValue('langcodes'));
     $projects = array_filter($form_state->getValue('projects_update'));
     // Set the translation import options. This determines if existing
     // translations will be overwritten by imported strings.
     $options = _locale_translation_default_update_options();
     // If the status was updated recently we can immediately start fetching the
     // translation updates. If the status is expired we clear it an run a batch to
     // update the status and then fetch the translation updates.
     $last_checked = $this->state->get('locale.translation_last_checked');
     if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) {
         locale_translation_clear_status();
         $batch = locale_translation_batch_update_build(array(), $langcodes, $options);
         batch_set($batch);
     } else {
         // Set a batch to download and import translations.
         $batch = locale_translation_batch_fetch_build($projects, $langcodes, $options);
         batch_set($batch);
         // Set a batch to update configuration as well.
         if ($batch = locale_config_batch_update_components($options, $langcodes)) {
             batch_set($batch);
         }
     }
 }