class LingotekSettingsTabPreferencesForm in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 4.0.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.0.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.1.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.2.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.3.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.4.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.5.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.6.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.7.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- 3.8.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
Configure Lingotek
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\lingotek\Form\LingotekConfigFormBase
- class \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm
- class \Drupal\lingotek\Form\LingotekConfigFormBase
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of LingotekSettingsTabPreferencesForm
1 string reference to 'LingotekSettingsTabPreferencesForm'
- LingotekSettingsController::content in src/
Controller/ LingotekSettingsController.php
File
- src/
Form/ LingotekSettingsTabPreferencesForm.php, line 12
Namespace
Drupal\lingotek\FormView source
class LingotekSettingsTabPreferencesForm extends LingotekConfigFormBase {
protected $lang_switcher_value = 0;
protected $top_level_value = 0;
protected $show_import_tab = 0;
protected $lang_switcher;
protected $lang_switcher_region;
protected $lang_regions;
protected $lang_region_selected;
protected $default_region = 'sidebar_first';
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'lingotek.settings_tab_preferences_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
$this
->retrieveImportSetting();
$this
->retrieveLanguageSwitcher();
$this
->retrieveAdminMenu();
$form['prefs'] = array(
'#type' => 'details',
'#title' => t('Preferences'),
);
$form['prefs']['lang_switcher'] = array(
'#type' => 'checkbox',
'#title' => 'Enable the default language switcher',
'#default_value' => $this->lang_switcher_value,
);
$form['prefs']['lang_switcher_select'] = array(
'#type' => 'select',
'#description' => $this
->t('The region where the switcher will be displayed') . '<br>' . $this
->t('Note: The default language switcher block is only shown if at least two languages are enabled and language negotiation is set to <em>URL</em> or <em>Session</em>. Go to <a href=":url">%language_detection</a> to change this.', [
'%language_detection' => $this
->t('Language detection and selection'),
':url' => Url::fromRoute('language.negotiation')
->toString(),
]),
'#options' => $this->lang_regions,
'#default_value' => $this->lang_region_selected == 'none' ? $this->default_region : $this->lang_region_selected,
'#states' => array(
'visible' => array(
':input[name="lang_switcher"]' => array(
'checked' => TRUE,
),
),
),
);
$form['prefs']['advanced_taxonomy_terms'] = array(
'#type' => 'checkbox',
'#title' => t('Enable advanced handling of taxonomy terms'),
'#description' => t('This option is used to handle translation of custom fields assigned to taxonomy terms.'),
'#default_value' => $this->lingotek
->get('preference.advanced_taxonomy_terms'),
);
$form['prefs']['hide_top_level'] = array(
'#type' => 'checkbox',
'#title' => t('Hide top-level menu item'),
'#description' => t('When hidden, the module can still be accessed under <i>Configuration > Regional and language</i>. <p> Note: It will take a few seconds to save if this setting is changed.'),
'#default_value' => $this->top_level_value,
);
$form['prefs']['show_language_labels'] = array(
'#type' => 'checkbox',
'#title' => t('Show language label on node pages'),
'#description' => t('If checked, language labels will be displayed for nodes that have the \'language selection\' field set to be visible.'),
'#default_value' => $this->lingotek
->get('preference.show_language_labels'),
);
$form['prefs']['always_show_translate_tabs'] = array(
'#type' => 'checkbox',
'#title' => t('Always show non-Lingotek translate tabs'),
'#description' => t('If checked, edit-form tabs for both Content Translation and Entity Translation will not be hidden, even if the entity is managed by Lingotek.'),
'#default_value' => $this->lingotek
->get('preference.always_show_translate_tabs'),
);
$form['prefs']['allow_local_editing'] = array(
'#prefix' => '<div style="margin-left: 20px;">',
'#suffix' => '</div>',
'#type' => 'checkbox',
'#title' => t('Allow local editing of Lingotek translations'),
'#description' => t('If checked, local editing of translations managed by Lingotek will be allowed. (Note: any changes made may be overwritten if the translation is downloaded from Lingotek again.)'),
'#default_value' => $this->lingotek
->get('preference.allow_local_editing'),
'#states' => array(
'visible' => array(
':input[name="always_show_translate_tabs"]' => array(
'checked' => TRUE,
),
),
),
);
$form['prefs']['language_specific_profiles'] = array(
'#type' => 'checkbox',
'#title' => t('Enable language-specific profiles'),
'#description' => t('If checked, languages enabled for Lingotek translation will not automatically be queued for all content. Instead, languages enabled for Lingotek will be added to the available languages for profiles but will be disabled by default on profiles that have existing content. (Note: this cannot be unchecked if language-specific settings are in use.)'),
'#default_value' => $this->lingotek
->get('preference.language_specific_profiles'),
);
$form['prefs']['delete_tms_documents_upon_disassociation'] = array(
'#type' => 'checkbox',
'#title' => t('Delete documents from Lingotek TMS when disassociating'),
'#description' => t('Your documents will remain in your Drupal site but will be deleted from the Lingotek TMS if this option is checked.'),
'#default_value' => $lingotek_config
->mustDeleteRemoteAfterDisassociation(),
);
$form['prefs']['advanced_parsing'] = array(
'#type' => 'checkbox',
'#title' => t('Enable advanced features'),
'#description' => t('Some features may not be available without an <a href=":url">Enterprise License</a> for the Lingotek TMS. Call <a href=":phone_link">%phone</a> for details.', [
':url' => 'http://www.lingotek.com',
':phone_link' => 'tel:1-801-331-7777',
'%phone' => '+1 (801) 331-7777',
]),
'#default_value' => $this->lingotek
->get('preference.advanced_parsing'),
);
$states = array(
'published' => t('Published'),
'unpublished' => t('Unpublished'),
'same-as-source' => t('Same as source content'),
);
$form['prefs']['target_download_status'] = array(
'#type' => 'select',
'#title' => t('Translations download publication status'),
'#description' => t('Translations download publication status: specify which published status the translations downloads must be saved with.'),
'#options' => $states,
'#default_value' => $lingotek_config
->getPreference('target_download_status') ?: 'same-as-source',
);
$form['prefs']['enable_content_cloud'] = array(
'#type' => 'checkbox',
'#title' => t('Enable importing from Lingotek Content Cloud (beta)'),
'#description' => t('Allows the importing of documents that are in your TMS. An \'Import\' tab will appear next to the \'Settings\' tab. <br> Note: The settings could take longer to save if this setting is changed.'),
'#default_value' => $this->lingotek
->get('preference.enable_content_cloud', FALSE),
);
$form['prefs']['actions']['#type'] = 'actions';
$form['prefs']['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#button_type' => 'primary',
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
$form_values = $form_state
->getValues();
$this
->saveAdminMenu($form_values);
$this
->saveLanguageSwitcherSettings($form_values);
$this
->saveShowLanguageFields($form_values);
$this
->saveAlwaysShowTranslateTabs($form_values);
$this->lingotek
->set('preference.language_specific_profiles', $form_values['language_specific_profiles']);
$this->lingotek
->set('preference.advanced_taxonomy_terms', $form_values['advanced_taxonomy_terms']);
$this->lingotek
->set('preference.advanced_parsing', $form_values['advanced_parsing']);
$lingotek_config
->setPreference('target_download_status', $form_values['target_download_status']);
$lingotek_config
->setDeleteRemoteAfterDisassociation($form_values['delete_tms_documents_upon_disassociation']);
parent::submitForm($form, $form_state);
}
protected function retrieveImportSetting() {
$this->show_import_tab = $this->lingotek
->get('preference.enable_content_cloud');
}
protected function retrieveLanguageSwitcher() {
if (\Drupal::moduleHandler()
->moduleExists('block')) {
$theme_default = $this
->config('system.theme')
->get('default');
$this->lang_regions = system_region_list($theme_default, REGIONS_VISIBLE);
$ids = \Drupal::entityQuery('block')
->condition('plugin', 'language_block:language_interface')
->condition('theme', $theme_default)
->execute();
if ($ids) {
// We just take the first language switcher.
$this->lang_switcher = \Drupal::entityManager()
->getStorage('block')
->load(reset($ids));
$this->lang_switcher_value = $this->lang_switcher
->status();
$this->lang_region_selected = $this->lang_switcher
->getRegion();
}
else {
$this->lang_switcher_value = 0;
$this->lang_region_selected = $this->default_region;
}
}
}
protected function saveLanguageSwitcherSettings($form_values) {
// If the website doesn't have a language switcher yet, don't act on it.
if ($this->lang_switcher) {
$this->lang_switcher
->setRegion($form_values['lang_switcher_select']);
if ($form_values['lang_switcher']) {
$this->lang_switcher
->enable();
}
else {
$this->lang_switcher
->disable();
}
$this->lang_switcher
->save();
}
else {
// If the user selects the checkbox, and no language switcher exists yet, create one.
if ($form_values['lang_switcher']) {
$config = $this
->config('system.theme');
$theme_default = $config
->get('default');
$this->lang_switcher = \Drupal::entityManager()
->getStorage('block')
->create(array(
'plugin' => 'language_block:language_interface',
'theme' => $theme_default,
));
$this->lang_switcher
->setRegion($form_values['lang_switcher_select']);
$this->lang_switcher
->enable();
$this->lang_switcher
->set('id', 'languageswitcher');
$this->lang_switcher
->save();
}
}
}
protected function retrieveAdminMenu() {
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$admin_menu = $menu_link_manager
->getDefinition('lingotek.dashboard');
// Will be opposite from enabled value since we're hiding the menu item
if ($admin_menu['enabled']) {
$this->top_level_value = 0;
}
else {
$this->top_level_value = 1;
}
}
protected function saveAdminMenu($form_values) {
$updated_values = [];
$should_reset_cache = FALSE;
/** @var MenuLinkManager $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
if ($this->show_import_tab != $form_values['enable_content_cloud']) {
$this->lingotek
->set('preference.enable_content_cloud', $form_values['enable_content_cloud']);
$should_reset_cache = TRUE;
}
// Only run if there's been a change to avoid clearing the cache if we don't have to
if ($this->top_level_value != $form_values['hide_top_level']) {
if ($form_values['hide_top_level']) {
$updated_values = array(
'enabled' => 0,
);
}
else {
$updated_values = array(
'enabled' => 1,
);
}
$menu_link_manager
->updateDefinition('lingotek.dashboard', $updated_values);
$ids = $menu_link_manager
->getChildIds('lingotek.dashboard');
foreach ($ids as $child_link) {
$menu_link_manager
->updateDefinition($child_link, $updated_values);
}
if ($updated_values['enabled']) {
$menu_link_manager
->resetLink('lingotek.dashboard');
}
$should_reset_cache = TRUE;
}
if ($should_reset_cache) {
drupal_flush_all_caches();
}
}
protected function saveAlwaysShowTranslateTabs($form_values) {
$this->lingotek
->set('preference.always_show_translate_tabs', $form_values['always_show_translate_tabs']);
if ($form_values['always_show_translate_tabs']) {
$this->lingotek
->set('preference.allow_local_editing', $form_values['allow_local_editing']);
}
else {
$this->lingotek
->set('preference.allow_local_editing', 0);
}
}
protected function saveShowLanguageFields($form_values) {
// Only save if there's a change to the show_language_labels choice
if ($this->lingotek
->get('preference.show_language_labels') != $form_values['show_language_labels']) {
$bundles = \Drupal::entityManager()
->getBundleInfo('node');
foreach ($bundles as $bundle_id => $bundle) {
if ($bundle['translatable']) {
$field_definitions = \Drupal::entityManager()
->getFieldDefinitions('node', $bundle_id);
$langcode = $field_definitions['langcode'];
$display = entity_get_display('node', $bundle_id, 'default');
if ($form_values['show_language_labels']) {
$component_values = array(
'type' => 'language',
'weight' => 0,
'settings' => array(),
'third_party_settings' => array(),
'label' => 'above',
);
$display
->setComponent('langcode', $component_values);
}
else {
$display
->removeComponent('langcode');
}
$display
->save();
}
}
}
$this->lingotek
->set('preference.show_language_labels', $form_values['show_language_labels']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
LingotekConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
3 |
LingotekConfigFormBase:: |
public | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
LingotekConfigFormBase:: |
public | function |
Constructs a \Drupal\lingotek\Form\LingotekConfigFormBase object. Overrides ConfigFormBase:: |
3 |
LingotekSettingsTabPreferencesForm:: |
protected | property | ||
LingotekSettingsTabPreferencesForm:: |
protected | property | ||
LingotekSettingsTabPreferencesForm:: |
protected | property | ||
LingotekSettingsTabPreferencesForm:: |
protected | property | ||
LingotekSettingsTabPreferencesForm:: |
protected | property | ||
LingotekSettingsTabPreferencesForm:: |
protected | property | ||
LingotekSettingsTabPreferencesForm:: |
protected | property | ||
LingotekSettingsTabPreferencesForm:: |
protected | property | ||
LingotekSettingsTabPreferencesForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
LingotekSettingsTabPreferencesForm:: |
public | function | ||
LingotekSettingsTabPreferencesForm:: |
protected | function | ||
LingotekSettingsTabPreferencesForm:: |
protected | function | ||
LingotekSettingsTabPreferencesForm:: |
protected | function | ||
LingotekSettingsTabPreferencesForm:: |
protected | function | ||
LingotekSettingsTabPreferencesForm:: |
protected | function | ||
LingotekSettingsTabPreferencesForm:: |
protected | function | ||
LingotekSettingsTabPreferencesForm:: |
protected | function | ||
LingotekSettingsTabPreferencesForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |