Commit d35e3cd8 authored by webchick's avatar webchick

Issue #1938014 by ACF: Convert locale's system_config_form() to SystemConfigFormBase.

parent 96903932
<?php
/**
* @file
* Contains \Drupal\user\LocaleSettingsForm.
*/
namespace Drupal\locale\Form;
use Drupal\system\SystemConfigFormBase;
/**
* Configure locale settings for this site.
*/
class LocaleSettingsForm extends SystemConfigFormBase {
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'locale_translate_settings';
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('locale.settings');
$form['update_interval_days'] = array(
'#type' => 'radios',
'#title' => t('Check for updates'),
'#default_value' => $config->get('translation.update_interval_days'),
'#options' => array(
'0' => t('Never (manually)'),
'1' => t('Daily'),
'7' => t('Weekly'),
),
'#description' => t('Select how frequently you want to check for new interface translations for your currently installed modules and themes. <a href="@url">Check updates now</a>.', array('@url' => url('admin/reports/translations/check'))),
);
$form['check_disabled_modules'] = array(
'#type' => 'checkbox',
'#title' => t('Check for updates of disabled modules and themes'),
'#default_value' => $config->get('translation.check_disabled_modules'),
);
if ($directory =config('locale.settings')->get('translation.path')) {
$description = t('Translation files are stored locally in the %path directory. You can change this directory on the <a href="@url">File system</a> configuration page.', array('%path' => $directory, '@url' => url('admin/config/media/file-system')));
}
else {
$description = t('Translation files will not be stored locally. Change the Interface translation directory on the <a href="@url">File system configuration</a> page.', array('@url' => url('admin/config/media/file-system')));
}
$form['#translation_directory'] = $directory;
$form['use_source'] = array(
'#type' => 'radios',
'#title' => t('Translation source'),
'#default_value' => $config->get('translation.use_source'),
'#options' => array(
LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL => t('Drupal translation server and local files'),
LOCALE_TRANSLATION_USE_SOURCE_LOCAL => t('Local files only'),
),
'#description' => t('The source of translation files for automatic interface translation.') . ' ' . $description,
);
if ($config->get('translation.overwrite_not_customized') == FALSE) {
$default = LOCALE_TRANSLATION_OVERWRITE_NONE;
}
elseif ($config->get('translation.overwrite_customized') == TRUE) {
$default = LOCALE_TRANSLATION_OVERWRITE_ALL;
}
else {
$default = LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED;
}
$form['overwrite'] = array(
'#type' => 'radios',
'#title' => t('Import behaviour'),
'#default_value' => $default,
'#options' => array(
LOCALE_TRANSLATION_OVERWRITE_NONE => t("Don't overwrite existing translations."),
LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED => t('Only overwrite imported translations, customized translations are kept.'),
LOCALE_TRANSLATION_OVERWRITE_ALL => t('Overwrite existing translations.'),
),
'#description' => t('How to treat existing translations when automatically updating the interface translations.'),
);
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, array &$form_state) {
parent::validateForm($form, $form_state);
if (empty($form['#translation_directory']) && $form_state['values']['use_source'] == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) {
form_set_error('use_source', t('You have selected local translation source, but no <a href="@url">Interface translation directory</a> was configured.', array('@url' => url('admin/config/media/file-system'))));
}
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$values = $form_state['values'];
$config = $this->configFactory->get('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);
break;
case LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED:
$config
->set('translation.overwrite_customized', FALSE)
->set('translation.overwrite_not_customized', TRUE);
break;
case LOCALE_TRANSLATION_OVERWRITE_NONE:
$config
->set('translation.overwrite_customized', FALSE)
->set('translation.overwrite_not_customized', FALSE);
break;
}
$config
->set('translation.check_disabled_modules', $values['check_disabled_modules'])
->save();
// Invalidate the cached translation status when the configuration setting of
// 'use_source' and 'check_disabled_modules' change.
if ($form['use_source']['#default_value'] != $form_state['values']['use_source'] ||
$form['check_disabled_modules']['#default_value'] != $form_state['values']['check_disabled_modules']) {
locale_translation_clear_status();
}
parent::submitForm($form, $form_state);
}
}
......@@ -215,12 +215,10 @@ function locale_menu() {
);
$items['admin/config/regional/translate/settings'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_translate_settings'),
'route_name' => 'locale_settings',
'access arguments' => array('translate interface'),
'weight' => 100,
'type' => MENU_LOCAL_TASK,
'file' => 'locale.pages.inc',
);
$items['admin/reports/translations'] = array(
'title' => 'Available translation updates',
......
......@@ -482,127 +482,6 @@ function locale_translation_manual_status() {
drupal_goto('admin/reports/translations');
}
/**
* Page callback: Configuration for interface translation.
*
* @see locale_menu()
*/
function locale_translate_settings($form, &$form_state) {
$config = config('locale.settings');
$form['update_interval_days'] = array(
'#type' => 'radios',
'#title' => t('Check for updates'),
'#default_value' => $config->get('translation.update_interval_days'),
'#options' => array(
'0' => t('Never (manually)'),
'1' => t('Daily'),
'7' => t('Weekly'),
),
'#description' => t('Select how frequently you want to check for new interface translations for your currently installed modules and themes. <a href="@url">Check updates now</a>.', array('@url' => url('admin/reports/translations/check'))),
);
$form['check_disabled_modules'] = array(
'#type' => 'checkbox',
'#title' => t('Check for updates of disabled modules and themes'),
'#default_value' => $config->get('translation.check_disabled_modules'),
);
if ($directory =config('locale.settings')->get('translation.path')) {
$description = t('Translation files are stored locally in the %path directory. You can change this directory on the <a href="@url">File system</a> configuration page.', array('%path' => $directory, '@url' => url('admin/config/media/file-system')));
}
else {
$description = t('Translation files will not be stored locally. Change the Interface translation directory on the <a href="@url">File system configuration</a> page.', array('@url' => url('admin/config/media/file-system')));
}
$form['#translation_directory'] = $directory;
$form['use_source'] = array(
'#type' => 'radios',
'#title' => t('Translation source'),
'#default_value' => $config->get('translation.use_source'),
'#options' => array(
LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL => t('Drupal translation server and local files'),
LOCALE_TRANSLATION_USE_SOURCE_LOCAL => t('Local files only'),
),
'#description' => t('The source of translation files for automatic interface translation.') . ' ' . $description,
);
if ($config->get('translation.overwrite_not_customized') == FALSE) {
$default = LOCALE_TRANSLATION_OVERWRITE_NONE;
}
elseif ($config->get('translation.overwrite_customized') == TRUE) {
$default = LOCALE_TRANSLATION_OVERWRITE_ALL;
}
else {
$default = LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED;
}
$form['overwrite'] = array(
'#type' => 'radios',
'#title' => t('Import behaviour'),
'#default_value' => $default,
'#options' => array(
LOCALE_TRANSLATION_OVERWRITE_NONE => t("Don't overwrite existing translations."),
LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED => t('Only overwrite imported translations, customized translations are kept.'),
LOCALE_TRANSLATION_OVERWRITE_ALL => t('Overwrite existing translations.'),
),
'#description' => t('How to treat existing translations when automatically updating the interface translations.'),
);
return system_config_form($form, $form_state);
}
/**
* Form validation handler for locale_translate_settings().
*
* @see locale_translate_settings()
*/
function locale_translate_settings_validate($form, &$form_state) {
if (empty($form['#translation_directory']) && $form_state['values']['use_source'] == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) {
form_set_error('use_source', t('You have selected local translation source, but no <a href="@url">Interface translation directory</a> was configured.', array('@url' => url('admin/config/media/file-system'))));
}
}
/**
* Form submission handler for locale_translate_settings().
*
* @see locale_translate_settings()
*/
function locale_translate_settings_submit($form, &$form_state) {
$values = $form_state['values'];
$config = 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);
break;
case LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED:
$config
->set('translation.overwrite_customized', FALSE)
->set('translation.overwrite_not_customized', TRUE);
break;
case LOCALE_TRANSLATION_OVERWRITE_NONE:
$config
->set('translation.overwrite_customized', FALSE)
->set('translation.overwrite_not_customized', FALSE);
break;
}
$config
->set('translation.check_disabled_modules', $values['check_disabled_modules'])
->save();
// Invalidate the cached translation status when the configuration setting of
// 'use_source' and 'check_disabled_modules' change.
if ($form['use_source']['#default_value'] != $form_state['values']['use_source'] ||
$form['check_disabled_modules']['#default_value'] != $form_state['values']['check_disabled_modules']) {
locale_translation_clear_status();
}
}
/**
* Page callback: Display the current translation status.
*
......
locale_settings:
pattern: '/admin/config/regional/translate/settings'
defaults:
_form: 'Drupal\locale\Form\LocaleSettingsForm'
requirements:
_permission: 'translate interface'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment