You are here

public function LingotekSettingsTabProfilesEditForm::buildForm in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 8 src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  2. 8.2 src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  3. 3.0.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  4. 3.1.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  5. 3.2.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  6. 3.3.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  7. 3.4.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  8. 3.5.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  9. 3.6.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  10. 3.7.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()
  11. 3.8.x src/Form/LingotekSettingsTabProfilesEditForm.php \Drupal\lingotek\Form\LingotekSettingsTabProfilesEditForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/LingotekSettingsTabProfilesEditForm.php, line 32

Class

LingotekSettingsTabProfilesEditForm
Configure Lingotek

Namespace

Drupal\lingotek\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this
    ->retrieveProfileFromUrl();
  $this
    ->retrieveProfileVaults();
  $this
    ->retrieveEnabledSettings();
  $form['defaults']['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Profile Name'),
    '#default_value' => ucwords($this->profile['name']),
    '#disabled' => $this->profile_name_disabled,
  ];
  $form['defaults']['current_future_note'] = [
    '#type' => 'markup',
    '#markup' => '<h3>' . t('Profile settings impacting all entities (new and existing)') . '</h3><hr />',
  ];
  $form['defaults']['auto_upload'] = [
    '#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'] = [
    '#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']['auto_download_worker'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use a Queue Worker to Download Translations'),
    '#description' => $this
      ->t('When enabled, completed translations will automatically be queued for download. This worker can be processed multiple ways, e.g. using cron.'),
    '#default_value' => $this->profile['auto_download_worker'],
  ];
  $form['defaults']['future_only_note'] = [
    '#type' => 'markup',
    '#markup' => '<h3>' . $this
      ->t('Profile settings impacting only new nodes') . '</h3><hr />',
  ];
  $form['defaults']['vault'] = [
    '#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'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#button_type' => 'primary',
  ];
  $form['defaults']['actions']['cancel'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Cancel'),
    '#button_type' => 'primary',
    '#submit' => [
      '::cancel',
    ],
  ];

  // User cannot delete a non-custom profile
  if (!$this->is_custom_id) {
    $form['defaults']['actions']['cant_delete_button'] = [
      '#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'] = [
      '#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'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Delete'),
      '#button_type' => 'primary',
      '#submit' => [
        '::deleteButton',
      ],
    ];
  }
  return $form;
}