class LingotekSettingsTabProfilesEditForm in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 4.0.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.0.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.1.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.2.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.3.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.4.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.5.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.6.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.7.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
- 3.8.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm
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\LingotekSettingsTabProfilesEditForm
- class \Drupal\lingotek\Form\LingotekConfigFormBase
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of LingotekSettingsTabProfilesEditForm
1 string reference to 'LingotekSettingsTabProfilesEditForm'
- LingotekSettingsController::profileForm in src/
Controller/ LingotekSettingsController.php
File
- src/
Form/ LingotekSettingsTabProfilesEditForm.php, line 16 - Contains \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm.
Namespace
Drupal\lingotek\FormView source
class LingotekSettingsTabProfilesEditForm extends LingotekConfigFormBase {
protected $profile;
protected $profile_vaults;
protected $auto_upload_disabled;
protected $auto_download_disabled;
protected $profile_name_disabled;
protected $profile_index;
protected $profile_usage;
protected $is_custom_id = 1;
// Disallow removing for now.
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'lingotek.settings_tab_profile_edit_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$this
->retrieveProfileFromUrl();
$this
->retrieveProfileVaults();
$this
->retrieveEnabledSettings();
$form['defaults']['name'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Profile Name'),
'#default_value' => $this
->t(ucwords($this->profile['name'])),
'#disabled' => $this->profile_name_disabled,
);
$form['defaults']['current_future_note'] = array(
'#type' => 'markup',
'#markup' => '<h3>' . t('Profile settings impacting all entities (new and existing)') . '</h3><hr />',
);
$form['defaults']['auto_upload'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Upload Content Automatically'),
'#description' => $this
->t('When enabled, your Drupal content (including saved edits) will automatically be uploaded to Lingotek for translation. When disabled, you are required to manually upload your content by clicking the "Upload" button on the Translations tab.'),
'#disabled' => $this->auto_upload_disabled,
'#default_value' => $this->profile['auto_upload'],
);
$form['defaults']['auto_download'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Download Translations Automatically'),
'#description' => $this
->t('When enabled, completed translations will automatically be downloaded from Lingotek. When disabled, you are required to manually download translations by clicking the "Download" button on the Translations tab.'),
'#disabled' => $this->auto_download_disabled,
'#default_value' => $this->profile['auto_download'],
);
$form['defaults']['future_only_note'] = array(
'#type' => 'markup',
'#markup' => '<h3>' . $this
->t('Profile settings impacting only new nodes') . '</h3><hr />',
);
$form['defaults']['vault'] = array(
'#type' => 'select',
'#title' => $this
->t('Default Vault'),
'#options' => $this->profile_vaults,
'#description' => $this
->t('The default Translation Memory Vault where translations are saved.'),
'#default_value' => FALSE,
);
$form['defaults']['actions']['#type'] = 'actions';
$form['defaults']['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#button_type' => 'primary',
);
$form['defaults']['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#button_type' => 'primary',
'#submit' => array(
'::cancel',
),
);
// User cannot delete a non-custom profile
if (!$this->is_custom_id) {
$form['defaults']['actions']['cant_delete_button'] = array(
'#type' => 'submit',
'#value' => $this
->t('This profile cannot be deleted'),
'#button_type' => 'primary',
'#disabled' => TRUE,
);
}
elseif ($this->profile_usage > 0 and $this->is_custom_id) {
$form['defaults']['actions']['cant_delete_usage_button'] = array(
'#type' => 'submit',
'#value' => $this
->t('You can only delete this profile when there are no entities or bundles using it'),
'#button_type' => 'primary',
'#disabled' => TRUE,
);
}
else {
$form['defaults']['actions']['delete'] = array(
'#type' => 'submit',
'#value' => $this
->t('Delete'),
'#button_type' => 'primary',
'#submit' => array(
'::deleteButton',
),
);
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_values = $form_state
->getValues();
// Save a new profile
if (!$this->profile) {
$this
->saveNewProfile(strtolower($form_values['name']), $form_values['auto_upload'], $form_values['auto_download']);
}
elseif ($this->is_custom_id) {
$this
->updateCustomProfile(strtolower($form_values['name']), $form_values['auto_upload'], $form_values['auto_download']);
}
$this->lingotek
->set('default.vault', $form_values['vault']);
$form_state
->setRedirect('lingotek.settings');
parent::submitForm($form, $form_state);
}
public function deleteButton(array &$form, FormStateInterface $form_state) {
if ($this->profile_usage == 0 and $this->is_custom_id) {
$this
->deleteCustomProfile();
}
drupal_set_message($this
->t('The profile has been deleted.'));
$form_state
->setRedirect('lingotek.settings');
}
public function cancel(array &$form, FormStateInterface $form_state) {
$form_state
->setRedirect('lingotek.settings');
}
protected function retrieveProfileFromUrl() {
if (isset($_GET['profile_choice']) and isset($_GET['profile_index']) and isset($_GET['profile_usage'])) {
$this->profile = LingotekProfile::load($_GET['profile_choice']);
$this->profile_index = $_GET['profile_index'];
$this->profile_usage = 1;
// $_GET['profile_usage'];
}
}
protected function retrieveProfileVaults() {
$personal_vault = [];
$personal_vault_key = $this->lingotek
->get('default.vault');
$community_vault = $this->lingotek
->get('account.resources.vault');
if (isset($community_vault[$personal_vault_key])) {
$personal_vault = array(
$personal_vault_key => $community_vault[$personal_vault_key],
);
}
$this->profile_vaults = array(
'Personal Vaults' => $personal_vault,
'Community Vaults' => $community_vault,
);
}
protected function retrieveEnabledSettings() {
// Adding a new profile
if (!$this->profile) {
$this->auto_upload_disabled = FALSE;
$this->auto_download_disabled = FALSE;
$this->profile_name_disabled = FALSE;
}
elseif (!$this->is_custom_id) {
$this->auto_upload_disabled = TRUE;
$this->auto_download_disabled = TRUE;
$this->profile_name_disabled = TRUE;
}
elseif ($this->is_custom_id) {
$this->auto_upload_disabled = FALSE;
$this->auto_download_disabled = FALSE;
$this->profile_name_disabled = FALSE;
}
}
protected function saveNewProfile($name, $auto_upload, $auto_download) {
$profile = LingotekProfile::create([
'id' => \Drupal::transliteration()
->transliterate($name),
'label' => $name,
'auto_upload' => $auto_upload,
'auto_download' => $auto_download,
]);
$profile
->save();
}
protected function updateCustomProfile($name, $auto_upload, $auto_download) {
/** @var LingotekProfile $current_profile */
$current_profile = $this->profile;
$current_profile
->set('label', $name);
$current_profile
->setAutomaticDownload($auto_download);
$current_profile
->setAutomaticUpload($auto_upload);
$current_profile
->save();
}
protected function deleteCustomProfile() {
$current_profile = $this->profile;
if (!$current_profile
->isLocked()) {
$current_profile
->save();
}
}
}
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 |
LingotekSettingsTabProfilesEditForm:: |
protected | property | ||
LingotekSettingsTabProfilesEditForm:: |
protected | property | ||
LingotekSettingsTabProfilesEditForm:: |
protected | property | ||
LingotekSettingsTabProfilesEditForm:: |
protected | property | ||
LingotekSettingsTabProfilesEditForm:: |
protected | property | ||
LingotekSettingsTabProfilesEditForm:: |
protected | property | ||
LingotekSettingsTabProfilesEditForm:: |
protected | property | ||
LingotekSettingsTabProfilesEditForm:: |
protected | property | ||
LingotekSettingsTabProfilesEditForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
LingotekSettingsTabProfilesEditForm:: |
public | function | ||
LingotekSettingsTabProfilesEditForm:: |
public | function | ||
LingotekSettingsTabProfilesEditForm:: |
protected | function | ||
LingotekSettingsTabProfilesEditForm:: |
public | function | ||
LingotekSettingsTabProfilesEditForm:: |
protected | function | ||
LingotekSettingsTabProfilesEditForm:: |
protected | function | ||
LingotekSettingsTabProfilesEditForm:: |
protected | function | ||
LingotekSettingsTabProfilesEditForm:: |
protected | function | ||
LingotekSettingsTabProfilesEditForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
LingotekSettingsTabProfilesEditForm:: |
protected | function | ||
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. |