Same name and namespace in other branches
  1. 8.9.x core/modules/forum/forum.module \forum_form_taxonomy_vocabulary_form_alter()
  2. 9 core/modules/forum/forum.module \forum_form_taxonomy_vocabulary_form_alter()

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

File

core/modules/forum/forum.module, line 303
Provides discussion forums.

Code

function forum_form_taxonomy_vocabulary_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $vid = \Drupal::config('forum.settings')
    ->get('vocabulary');
  $vocabulary = $form_state
    ->getFormObject()
    ->getEntity();
  if ($vid == $vocabulary
    ->id()) {
    $form['help_forum_vocab'] = [
      '#markup' => t('This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'),
      '#weight' => -1,
    ];

    // Forum's vocabulary always has single hierarchy. Forums and containers
    // have only one parent or no parent for root items. By default this value
    // is 0.
    $form['hierarchy']['#value'] = VocabularyInterface::HIERARCHY_SINGLE;

    // Do not allow to delete forum's vocabulary.
    $form['actions']['delete']['#access'] = FALSE;

    // Do not allow to change a vid of forum's vocabulary.
    $form['vid']['#disabled'] = TRUE;
  }
}