You are here

public function LingotekElementInfoAlterForm::process in Lingotek Translation 3.4.x

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

Process callback: Expands the language_configuration form element.

Parameters

array $element: Form API element.

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

array $form: The form.

Return value

array Processed language configuration element.

File

src/Form/LingotekElementInfoAlterForm.php, line 114

Class

LingotekElementInfoAlterForm
Adds the option to use Lingotek to translate content entities

Namespace

Drupal\lingotek\Form

Code

public function process(array $element, FormStateInterface $form_state, array &$form) {
  if (empty($element['#content_translation_for_lingotek_skip_alter']) && $this->currentUser
    ->hasPermission('administer content translation') && $this->currentUser
    ->hasPermission('administer lingotek')) {
    $key = $element['#name'];
    $form_state
      ->set([
      'content_translation_for_lingotek',
      'key',
    ], $key);
    $context = $form_state
      ->get([
      'language',
      $key,
    ]);
    $entity_type_id = $context['entity_type'];
    $bundle_id = $context['bundle'];
    if ($form['form_id']['#value'] !== 'language_content_settings_form') {
      $element['content_translation_for_lingotek'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Enable translation for Lingotek'),
        '#description' => $this
          ->t('This will enable Lingotek translation for this bundle, and will enable default fields for translation. You can <a href=":settings">review those settings</a> later.', [
          ':settings' => Url::fromRoute('lingotek.settings')
            ->toString(),
        ]),
        '#default_value' => $context['bundle'] !== NULL && $this->lingotekConfiguration
          ->isEnabled($context['entity_type'], $context['bundle']),
        '#states' => [
          'visible' => [
            ':input[name="language_configuration[content_translation]"]' => [
              'checked' => TRUE,
            ],
          ],
        ],
      ];
      $submit_name = isset($form['actions']['save_continue']) ? 'save_continue' : 'submit';

      // Only add the submit handler on the submit button if the #submit property
      // is already available, otherwise this breaks the form submit function.
      if (isset($form['actions'][$submit_name]['#submit'])) {
        $form['actions'][$submit_name]['#submit'][] = [
          $this,
          'submit',
        ];
      }
      else {
        $form['#submit'][] = [
          $this,
          'submit',
        ];
      }
    }
  }
  return $element;
}