You are here

public function DemoNode::createGroupContent in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  2. 8 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  3. 8.2 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  4. 8.3 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  5. 8.4 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  6. 8.5 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  7. 8.6 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  8. 8.7 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  9. 8.8 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  10. 10.3.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  11. 10.0.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()
  12. 10.1.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createGroupContent()

Creates a group content.

Parameters

\Drupal\node\NodeInterface $entity: Object of a node.

string $uuid: UUID of a group.

1 call to DemoNode::createGroupContent()
DemoNode::createContent in modules/custom/social_demo/src/DemoNode.php
Creates content.

File

modules/custom/social_demo/src/DemoNode.php, line 174

Class

DemoNode
Class DemoNode.

Namespace

Drupal\social_demo

Code

public function createGroupContent(NodeInterface $entity, $uuid) {

  // Load the group.
  $groups = $this->groupStorage
    ->loadByProperties([
    'uuid' => $uuid,
  ]);
  if ($groups) {
    $group = current($groups);

    // Get the group content plugin.
    $plugin_id = 'group_node:' . $entity
      ->bundle();
    $plugin = $group
      ->getGroupType()
      ->getContentPlugin($plugin_id);
    $group_content = GroupContent::create([
      'type' => $plugin
        ->getContentTypeConfigId(),
      'gid' => $group
        ->id(),
      'entity_id' => $entity
        ->id(),
    ]);
    $group_content
      ->save();
  }
}