function forum_form_node_form_alter in Drupal 10
Same name and namespace in other branches
- 8 core/modules/forum/forum.module \forum_form_node_form_alter()
- 7 modules/forum/forum.module \forum_form_node_form_alter()
- 9 core/modules/forum/forum.module \forum_form_node_form_alter()
Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
File
- core/
modules/ forum/ forum.module, line 322 - 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'] = [
'#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'] = [
'#type' => 'value',
'#value' => $node->forum_tid,
];
}
if (isset($form['taxonomy_forums'])) {
$widget =& $form['taxonomy_forums']['widget'];
$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 : '';
}
}
}