function forum_form_taxonomy_vocabulary_form_alter

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

File

core/modules/forum/forum.module, line 289

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;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.