View source
<?php
namespace Drupal\opigno_learning_path;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\group\Entity\GroupContent;
class JoinService {
protected $currentUser;
protected $entityFormBuilder;
public function __construct(AccountInterface $current_user, EntityFormBuilderInterface $entity_form_builder) {
$this->currentUser = $current_user;
$this->entityFormBuilder = $entity_form_builder;
}
public function getForm($group) {
$plugin = $group
->getGroupType()
->getContentPlugin('group_membership');
$group_content = GroupContent::create([
'type' => $plugin
->getContentTypeConfigId(),
'gid' => $group
->id(),
'entity_id' => $this->currentUser
->id(),
]);
return $this->entityFormBuilder
->getForm($group_content, 'group-join');
}
}