How to add node to group?

Created on 1 January 2024, 6 months ago
Updated 2 January 2024, 6 months ago

Problem/Motivation

Spent a couple hours trying to piece together bits of changes on how to add content to a group; but still no luck.

I used to (1.x) do this:

  // loop through each type to see if is Group-able
  $plugins = $group->getGroupType()->getInstalledContentPlugins();
  foreach ($plugins as $plugin_id => $plugin) {
    if (str_replace($group_type . ':', '', $plugin->getConfiguration()['id']) == $entity->bundle()) {
      $group->addContent($entity, $plugin->getConfiguration()['id']);
      $company = $group->get('label')->getString();
      \Drupal::messenger()->addMessage(t('%content added to %company: %company', [
        '%content' => $entity->getTitle(),
        '%company' => $company]),
        'notice');
    }
  }

any hints on how to do this now?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Documentation

Created by

πŸ‡¨πŸ‡¦Canada liquidcms

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @liquidcms
  • πŸ‡¨πŸ‡¦Canada liquidcms

    just had to change the getPlugins method:

      $plugins = $group->getGroupType()->getInstalledPlugins();
      foreach ($plugins as $plugin_id => $plugin) {
        if (str_replace($group_type . ':', '', $plugin->getConfiguration()['id']) == $entity->bundle()) {
          $group->addRelationship($entity, $plugin->getConfiguration()['id']);
          $company = $group->get('label')->getString();
          \Drupal::messenger()->addMessage(t('%content added to %company: %company', [
            '%content' => $entity->getTitle(),
            '%company' => $company]),
            'notice');
        }
      }
    

    although i am guessing it isn't necessary to loop through all the plugins to do this.

Production build 0.69.0 2024