May 29, 2020 in Drupal 8

The forum module is a core module that was rewritten for drupal 8. In this snippet I show you how to create forum topics programmatically.

use Drupal\node\Entity\Node;

    $node = Node::create(array(
      'type' => 'forum',
      'title' => $title,
      'langcode' => 'nl',
      'uid' => $uid,
      'status' => 1,
      'taxonomy_forums' => array(2), // The term id of your forum should be here!
    ));