You are here

function opigno_forum_form_node_form_alter in Opigno forum 8

Same name and namespace in other branches
  1. 3.x opigno_forum.module \opigno_forum_form_node_form_alter()

Implements hook_form_BASE_FORM_ID_alter().

File

./opigno_forum.module, line 194
Contains opigno_forum.module.

Code

function opigno_forum_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (isset($form['taxonomy_forums'])) {

    // Hide forums that current user can't access from the forum fields.
    $account = \Drupal::currentUser();
    $widget =& $form['taxonomy_forums']['widget'];
    $options = $widget['#options'];
    foreach ($options as $tid => $title) {
      if (!is_numeric($tid)) {
        continue;
      }
      if (!_opigno_forum_access($tid, $account)) {
        unset($widget['#options'][$tid]);
      }
    }
  }
}