Commit 0636ac8f authored by James Candan's avatar James Candan
Browse files

Issue #3114431 by jcandan, maurizio.ganovelli: Call to a member function addContent() on null

parent bfb76e81
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -125,12 +125,21 @@ function group_mapping_from_node_custom_submit(&$form, FormStateInterface $form_
  if (!empty($group_ids)) {
    $plugin = 'group_node:' . $node->getType();
    foreach ($group_ids as $group_id) {

      // During node creation $group_id is an array, we need to extract target_id key.
      if (isset($group_id['target_id'])) {
        $group_id = $group_id['target_id'];
      }

      // Load the Group to be added to the node.
      $group = Drupal::entityTypeManager()->getStorage('group')->load($group_id);

      // Map node with chosen group.
      if ($group) {
        $group->addContent($node, $plugin);
      }

    }
  }
}