You are here

public function LockFieldsFormManager::addLockFieldsListToForm in TMGMT Translator Smartling 8.4

Extends given form array with 'Lock fields' tab.

Parameters

$form:

FormStateInterface $form_state:

Return value

array

File

src/Smartling/LockFields/LockFieldsFormManager.php, line 37

Class

LockFieldsFormManager
Class LockFieldsFormManager

Namespace

Drupal\tmgmt_smartling\Smartling\LockFields

Code

public function addLockFieldsListToForm(array &$form, FormStateInterface $form_state) {
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $entity_lang_code = $entity
    ->get('default_langcode')
    ->getLangcode();
  $default_site_lang_code = $this->languageManager
    ->getDefaultLanguage()
    ->getId();
  $translatable_fields = $this->lockFieldsManager
    ->getTranslatableFieldsByContentEntity($entity);
  if ($entity_lang_code != $default_site_lang_code) {
    $form['smartling'] = [
      '#type' => 'details',
      '#title' => new TranslatableMarkup('Smartling management'),
      '#group' => 'advanced',
      '#attached' => [
        'drupalSettings' => [
          'smartling' => [
            'checkAllId' => [
              'edit-locked-fields',
            ],
          ],
        ],
        'library' => [
          'tmgmt_smartling/checkAll',
        ],
      ],
    ];
    $form['smartling']['locked_fields'] = [
      '#title' => new TranslatableMarkup('Lock fields'),
      '#type' => 'checkboxes',
      '#description' => t('Selected fields will not be overwritten.'),
      '#options' => $translatable_fields,
      '#default_value' => $this->lockFieldsManager
        ->getLockedFieldsByContentEntity($entity),
    ];
    $form['smartling']['locked_fields']['check_all'] = [
      '#weight' => 1,
      '#markup' => '<div class="check-control"><a href="#" class="check-all">' . new TranslatableMarkup('Check all / Uncheck All') . '</a></div>',
    ];
    $form['actions']['submit']['#submit'][] = [
      LockFieldsFormManager::class,
      'submitLockFieldsList',
    ];
  }
}