You are here

thunder_taxonomy.module in Thunder 6.2.x

Module for adding custom Infinity base functions.

File

modules/thunder_taxonomy/thunder_taxonomy.module
View source
<?php

/**
 * @file
 * Module for adding custom Infinity base functions.
 */
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_entity_type_alter().
 */
function thunder_taxonomy_entity_type_alter(array &$entity_types) {

  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
  if (!empty($entity_types['taxonomy_term'])) {
    $entity_types['taxonomy_term']
      ->setAccessClass('Drupal\\thunder_taxonomy\\ThunderTermAccessControlHandler');
  }
}

/**
 * Implements hook_form_BASE_FORM_ID_alter() for \Drupal\taxonomy\TermForm.
 */
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';
  }
}

/**
 * Implements hook_form_taxonomy_overview_terms_alter().
 */
function thunder_taxonomy_form_taxonomy_overview_terms_alter(&$form, FormStateInterface $formState) {
  $form['terms']['#header'] = array_merge(array_slice($form['terms']['#header'], 0, 1, TRUE), [
    t('Status'),
  ], array_slice($form['terms']['#header'], 1, NULL, TRUE));
  foreach ($form['terms'] as &$term) {
    if (is_array($term) && !empty($term['#term'])) {
      $status['status'] = [
        '#markup' => $term['#term']->status->value ? t('Published') : t('Unpublished'),
        '#type' => 'item',
      ];
      $term = array_slice($term, 0, 1, TRUE) + $status + array_slice($term, 1, NULL, TRUE);
    }
  }
}