/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = array();
     // Initialize a language list to the ones available, including English.
     $languages = $this->languageManager->getLanguages();
     $existing_languages = array();
     foreach ($languages as $langcode => $language) {
         $existing_languages[$langcode] = $language->getName();
     }
     // If we have no languages available, present the list of predefined languages
     // only. If we do have already added languages, set up two option groups with
     // the list of existing and then predefined languages.
     if (empty($existing_languages)) {
         $language_options = $this->languageManager->getStandardLanguageListWithoutConfigured();
     } else {
         $language_options = array($this->t('Existing languages') => $existing_languages, $this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured());
     }
     $form['mappings'] = array('#tree' => TRUE, '#theme' => 'language_negotiation_configure_browser_form_table');
     $mappings = $this->language_get_browser_drupal_langcode_mappings();
     foreach ($mappings as $browser_langcode => $drupal_langcode) {
         $form['mappings'][$browser_langcode] = array('browser_langcode' => array('#title' => $this->t('Browser language code'), '#title_display' => 'invisible', '#type' => 'textfield', '#default_value' => $browser_langcode, '#size' => 20, '#required' => TRUE), 'drupal_langcode' => array('#title' => $this->t('Site language'), '#title_display' => 'invisible', '#type' => 'select', '#options' => $language_options, '#default_value' => $drupal_langcode, '#required' => TRUE));
     }
     // Add empty row.
     $form['new_mapping'] = array('#type' => 'details', '#title' => $this->t('Add a new mapping'), '#tree' => TRUE);
     $form['new_mapping']['browser_langcode'] = array('#type' => 'textfield', '#title' => $this->t('Browser language code'), '#description' => $this->t('Use language codes as <a href="@w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', array('@w3ctags' => 'http://www.w3.org/International/articles/language-tags/')), '#size' => 20);
     $form['new_mapping']['drupal_langcode'] = array('#type' => 'select', '#title' => $this->t('Site language'), '#options' => $language_options);
     return parent::buildForm($form, $form_state);
 }
Пример #2
0
 /**
  * Form constructor for the translation import screen.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $languages = $this->languageManager->getLanguages();
     // Initialize a language list to the ones available, including English if we
     // are to translate Drupal to English as well.
     $existing_languages = array();
     foreach ($languages as $langcode => $language) {
         if ($langcode != 'en' || locale_translate_english()) {
             $existing_languages[$langcode] = $language->getName();
         }
     }
     // If we have no languages available, present the list of predefined
     // languages only. If we do have already added languages, set up two option
     // groups with the list of existing and then predefined languages.
     if (empty($existing_languages)) {
         $language_options = $this->languageManager->getStandardLanguageListWithoutConfigured();
         $default = key($language_options);
     } else {
         $default = key($existing_languages);
         $language_options = array($this->t('Existing languages') => $existing_languages, $this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured());
     }
     $validators = array('file_validate_extensions' => array('po'), 'file_validate_size' => array(file_upload_max_size()));
     $form['file'] = array('#type' => 'file', '#title' => $this->t('Translation file'), '#description' => array('#theme' => 'file_upload_help', '#description' => $this->t('A Gettext Portable Object file.'), '#upload_validators' => $validators), '#size' => 50, '#upload_validators' => $validators, '#attributes' => array('class' => array('file-import-input')));
     $form['langcode'] = array('#type' => 'select', '#title' => $this->t('Language'), '#options' => $language_options, '#default_value' => $default, '#attributes' => array('class' => array('langcode-input')));
     $form['customized'] = array('#title' => $this->t('Treat imported strings as custom translations'), '#type' => 'checkbox');
     $form['overwrite_options'] = array('#type' => 'container', '#tree' => TRUE);
     $form['overwrite_options']['not_customized'] = array('#title' => $this->t('Overwrite non-customized translations'), '#type' => 'checkbox', '#states' => array('checked' => array(':input[name="customized"]' => array('checked' => TRUE))));
     $form['overwrite_options']['customized'] = array('#title' => $this->t('Overwrite existing customized translations'), '#type' => 'checkbox');
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Import'));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $link = '')
 {
     $query = db_select('xmlsitemap');
     $query->fields('xmlsitemap');
     $query->condition('type', 'custom');
     $query->condition('id', $link);
     $result = $query->execute();
     $link = $result->fetchAssoc();
     if (!$link) {
         drupal_set_message(t('No valid custom link specified.'), 'error');
         return new RedirectResponse('/admin/config/search/xmlsitemap/custom/');
     } else {
         $this->custom_link = $link;
     }
     $query = db_select('xmlsitemap', 'x');
     $query->addExpression('MAX(id)');
     $id = $query->execute()->fetchField();
     $this->custom_link += array('id' => $id + 1, 'loc' => '', 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, 'lastmod' => 0, 'changefreq' => 0, 'changecount' => 0, 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED);
     $form['type'] = array('#type' => 'value', '#value' => 'custom');
     $form['id'] = array('#type' => 'value', '#value' => $this->custom_link['id']);
     $form['loc'] = array('#type' => 'textfield', '#title' => t('Path to link'), '#field_prefix' => Url::fromRoute('<front>', [], array('absolute' => TRUE)), '#default_value' => $this->custom_link['loc'], '#required' => TRUE, '#size' => 30);
     $form['priority'] = array('#type' => 'select', '#title' => t('Priority'), '#options' => xmlsitemap_get_priority_options(), '#default_value' => number_format($this->custom_link['priority'], 1), '#description' => t('The priority of this URL relative to other URLs on your site.'));
     $form['changefreq'] = array('#type' => 'select', '#title' => t('Change frequency'), '#options' => array(0 => t('None')) + xmlsitemap_get_changefreq_options(), '#default_value' => $link['changefreq'], '#description' => t('How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page.'));
     $languages = $this->languageManager->getLanguages();
     $languages_list = array();
     foreach ($languages as $key => $value) {
         $languages_list[$key] = $value->getName();
     }
     $form['language'] = array('#type' => 'select', '#title' => t('Language'), '#default_value' => $this->custom_link['language'], '#options' => array(LanguageInterface::LANGCODE_NOT_SPECIFIED => t('Language neutral')) + $languages_list, '#access' => $languages_list);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 5);
     $cancel_link = Url::fromRoute('xmlsitemap_custom.list');
     $form['actions']['cancel'] = array('#markup' => l(t('Cancel'), $cancel_link), '#weight' => 10);
     return $form;
 }
Пример #4
0
 /**
  * Performs language negotiation using the specified negotiation method.
  *
  * @param string $type
  *   The language type to be initialized.
  * @param string $method_id
  *   The string identifier of the language negotiation method to use to detect
  *   language.
  *
  * @return \Drupal\Core\Language\LanguageInterface|null
  *   Negotiated language object for given type and method, FALSE otherwise.
  */
 protected function negotiateLanguage($type, $method_id)
 {
     $langcode = NULL;
     $method = $this->negotiatorManager->getDefinition($method_id);
     if (!isset($method['types']) || in_array($type, $method['types'])) {
         $langcode = $this->getNegotiationMethodInstance($method_id)->getLangcode($this->requestStack->getCurrentRequest());
     }
     $languages = $this->languageManager->getLanguages();
     return isset($languages[$langcode]) ? $languages[$langcode] : NULL;
 }
Пример #5
0
 /**
  * Updates all configuration translations for the names / languages provided.
  *
  * To be used when interface translation changes result in the need to update
  * configuration translations to keep them in sync.
  *
  * @param array $names
  *   Array of names of configuration objects to update.
  * @param array $langcodes
  *   (optional) Array of language codes to update. Defaults to all
  *   configurable languages.
  *
  * @return int
  *   Total number of configuration override and active configuration objects
  *   updated (saved or removed).
  */
 public function updateConfigTranslations(array $names, array $langcodes = array())
 {
     $langcodes = $langcodes ? $langcodes : array_keys($this->languageManager->getLanguages());
     $count = 0;
     foreach ($names as $name) {
         $translatable = $this->getTranslatableDefaultConfig($name);
         if (empty($translatable)) {
             // If there is nothing translatable in this configuration or not
             // supported, skip it.
             continue;
         }
         $active_langcode = $this->getActiveConfigLangcode($name);
         $active = $this->configStorage->read($name);
         foreach ($langcodes as $langcode) {
             $processed = $this->processTranslatableData($name, $active, $translatable, $langcode);
             if ($langcode != $active_langcode) {
                 // If the language code is not the same as the active storage
                 // language, we should update a configuration override.
                 if (!empty($processed)) {
                     // Update translation data in configuration override.
                     $this->saveTranslationOverride($name, $langcode, $processed);
                     $count++;
                 } else {
                     $override = $this->languageManager->getLanguageConfigOverride($langcode, $name);
                     if (!$override->isNew()) {
                         $data = $this->filterOverride($override->get(), $translatable);
                         if (empty($data)) {
                             // Delete language override if there is no data left at all.
                             // This means all prior translations in the override were locale
                             // managed.
                             $this->deleteTranslationOverride($name, $langcode);
                             $count++;
                         } else {
                             // If there were translatable elements besides locale managed
                             // items, save with only those, and remove the ones managed
                             // by locale only.
                             $this->saveTranslationOverride($name, $langcode, $data);
                             $count++;
                         }
                     }
                 }
             } elseif (locale_is_translatable($langcode)) {
                 // If the language code is the active storage language, we should
                 // update. If it is English, we should only update if English is also
                 // translatable.
                 $active = NestedArray::mergeDeepArray(array($active, $processed), TRUE);
                 $this->saveTranslationActive($name, $active);
                 $count++;
             }
         }
     }
     return $count;
 }
 /**
  * Updates all configuration translations for the names / languages provided.
  *
  * To be used when interface translation changes result in the need to update
  * configuration translations to keep them in sync.
  *
  * @param array $names
  *   Array of names of configuration objects to update.
  * @param array $langcodes
  *   (optional) Array of language codes to update. Defaults to all
  *   configurable languages.
  *
  * @return int
  *   Total number of configuration override and active configuration objects
  *   updated (saved or removed).
  */
 public function updateConfigTranslations(array $names, array $langcodes = array())
 {
     $langcodes = $langcodes ? $langcodes : array_keys($this->languageManager->getLanguages());
     $count = 0;
     foreach ($names as $name) {
         $translatable = $this->getTranslatableDefaultConfig($name);
         if (empty($translatable)) {
             // If there is nothing translatable in this configuration or not
             // supported, skip it.
             continue;
         }
         $active_langcode = $this->getActiveConfigLangcode($name);
         $active = $this->configStorage->read($name);
         foreach ($langcodes as $langcode) {
             $processed = $this->processTranslatableData($name, $active, $translatable, $langcode);
             // If the language code is not the same as the active storage
             // language, we should update the configuration override.
             if ($langcode != $active_langcode) {
                 $override = $this->languageManager->getLanguageConfigOverride($langcode, $name);
                 // Filter out locale managed configuration keys so that translations
                 // removed from Locale will be reflected in the config override.
                 $data = $this->filterOverride($override->get(), $translatable);
                 if (!empty($processed)) {
                     // Merge in the Locale managed translations with existing data.
                     $data = NestedArray::mergeDeepArray(array($data, $processed), TRUE);
                 }
                 if (empty($data) && !$override->isNew()) {
                     // The configuration override contains Locale overrides that no
                     // longer exist.
                     $this->deleteTranslationOverride($name, $langcode);
                     $count++;
                 } elseif (!empty($data)) {
                     // Update translation data in configuration override.
                     $this->saveTranslationOverride($name, $langcode, $data);
                     $count++;
                 }
             } elseif (locale_is_translatable($langcode)) {
                 // If the language code is the active storage language, we should
                 // update. If it is English, we should only update if English is also
                 // translatable.
                 $active = NestedArray::mergeDeepArray(array($active, $processed), TRUE);
                 $this->saveTranslationActive($name, $active);
                 $count++;
             }
         }
     }
     return $count;
 }
Пример #7
0
 /**
  * Performs language negotiation using the specified negotiation method.
  *
  * @param string $type
  *   The language type to be initialized.
  * @param string $method_id
  *   The string identifier of the language negotiation method to use to detect
  *   language.
  *
  * @return \Drupal\Core\Language\LanguageInterface|null
  *   Negotiated language object for given type and method, FALSE otherwise.
  */
 protected function negotiateLanguage($type, $method_id)
 {
     $langcode = NULL;
     $method = $this->negotiatorManager->getDefinition($method_id);
     if (!isset($method['types']) || in_array($type, $method['types'])) {
         // Check for a cache mode force from settings.php.
         if ($this->settings->get('page_cache_without_database')) {
             $cache_enabled = TRUE;
         } else {
             $cache_enabled = $this->configFactory->get('system.performance')->get('cache.page.use_internal');
         }
         // If the language negotiation method has no cache preference or this is
         // satisfied we can execute the callback.
         if ($cache = !isset($method['cache']) || $this->currentUser->isAuthenticated() || $method['cache'] == $cache_enabled) {
             $langcode = $this->getNegotiationMethodInstance($method_id)->getLangcode($this->requestStack->getCurrentRequest());
         }
     }
     $languages = $this->languageManager->getLanguages();
     return isset($languages[$langcode]) ? $languages[$langcode] : NULL;
 }