function forum_form_node_form_alter

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

Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.

File

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

Code

function forum_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $node = $form_state->getFormObject()->getEntity();
  if (isset($node->taxonomy_forums) && !$node->isNew()) {
    $forum_terms = $node->taxonomy_forums;
    // If editing, give option to leave shadows.
    $shadow = (count($forum_terms) > 1);
    $form['shadow'] = array(
      '#type' => 'checkbox',
      '#title' => t('Leave shadow copy'),
      '#default_value' => $shadow,
      '#description' => t('If you move this topic, you can leave a link in the old forum to the new forum.'),
    );
    $form['forum_tid'] = array('#type' => 'value', '#value' => $node->forum_tid);
  }

  if (isset($form['taxonomy_forums'])) {
    $widget = &$form['taxonomy_forums']['widget'];
    // Make the vocabulary required for 'real' forum-nodes.
    $widget['#required'] = TRUE;
    $widget['#multiple'] = FALSE;
    if (empty($widget['#default_value'])) {
      // If there is no default forum already selected, try to get the forum
      // ID from the URL (e.g., if we are on a page like node/add/forum/2, we
      // expect "2" to be the ID of the forum that was requested).
      $requested_forum_id = \Drupal::request()->query->get('forum_id');
      $widget['#default_value'] = is_numeric($requested_forum_id) ? $requested_forum_id : '';
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!forum!forum.module/function/forum_form_node_form_alter/8.1.x