forum_form_taxonomy_vocabulary_form_alter

forum_form_taxonomy_vocabulary_form_alter(&$form, FormStateInterface $form_state, $form_id)

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

File

core/modules/forum/forum.module, line 288
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'] = array(
      '#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;
  }
}
doc_Drupal
2016-10-29 09:17:18
Comments
Leave a Comment

Please login to continue.