You are here

public function ForumTopicHandler::onNodeInsert in Opigno forum 3.x

Same name and namespace in other branches
  1. 8 src/ForumTopicHandler.php \Drupal\opigno_forum\ForumTopicHandler::onNodeInsert()

Performs node creation tasks.

Parameters

\Drupal\node\NodeInterface $node: A newly created node.

File

src/ForumTopicHandler.php, line 73

Class

ForumTopicHandler
Handles the relationship between forum topics and groups.

Namespace

Drupal\opigno_forum

Code

public function onNodeInsert(NodeInterface $node) {
  $node_type_id = $node
    ->bundle();
  if ($this
    ->isForumTopicType($node_type_id) && $this
    ->isLearningPathContent($node_type_id) && ($gid = $this
    ->getForumTopicGroupId($node))) {

    /** @var \Drupal\group\Entity\GroupInterface $group */
    $group = $this->entityTypeManager
      ->getStorage('group')
      ->load($gid);

    // The target entity will be saved again while being added to the group,
    // which would trigger recursive save and integrity constraint violation
    // issues in the forum integration logic.
    // @todo Perform the addition here once Group deals with additions in a
    //   saner way. See https://www.drupal.org/node/2892512#comment-12821461.
    drupal_register_shutdown_function(function () use ($group, $node) {
      $group
        ->addContent($node, 'group_node:' . $node
        ->bundle());
    });
  }
}