You are here

function thunder_taxonomy_form_taxonomy_term_form_alter in Thunder 6.2.x

Implements hook_form_BASE_FORM_ID_alter() for \Drupal\taxonomy\TermForm.

File

modules/thunder_taxonomy/thunder_taxonomy.module, line 24
Module for adding custom Infinity base functions.

Code

function thunder_taxonomy_form_taxonomy_term_form_alter(&$form, FormStateInterface $form_state) {

  // @todo Remove after seven / thunder_admin support is dropped.
  $activeTheme = Drupal::theme()
    ->getActiveTheme()
    ->getName();
  if (in_array($activeTheme, [
    'seven',
    'thunder_admin',
  ])) {

    // Create sidebar group.
    $form['advanced'] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'entity-meta',
        ],
      ],
      '#weight' => 99,
    ];

    // Use the same form like node edit.
    $form['#theme'] = [
      'node_edit_form',
    ];
    $form['#attached']['library'][] = 'seven/node-form';

    // Move relations into sidebar.
    $form['relations']['#group'] = 'advanced';

    /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
    $form_object = $form_state
      ->getFormObject();

    /** @var \Drupal\taxonomy\TermInterface $term */
    $term = $form_object
      ->getEntity();

    // Move pathauto into sidebar.
    $form['path_settings'] = [
      '#type' => 'details',
      '#title' => t('URL path settings'),
      '#open' => !empty($form['path']['widget'][0]['alias']['#value']),
      '#group' => 'advanced',
      '#access' => !empty($form['path']['#access']) && $term
        ->hasField('path') && $term
        ->get('path')
        ->access('edit'),
      '#attributes' => [
        'class' => [
          'path-form',
        ],
      ],
      '#attached' => [
        'library' => [
          'path/drupal.path',
        ],
      ],
      '#weight' => 30,
    ];
    $form['path']['#group'] = 'path_settings';
  }
}