You are here

class JoinService in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/JoinService.php \Drupal\opigno_learning_path\JoinService

Class JoinService.

Hierarchy

Expanded class hierarchy of JoinService

1 string reference to 'JoinService'
opigno_learning_path.services.yml in ./opigno_learning_path.services.yml
opigno_learning_path.services.yml
1 service uses JoinService
opigno_learning_path.join_form in ./opigno_learning_path.services.yml
Drupal\opigno_learning_path\JoinService

File

src/JoinService.php, line 12

Namespace

Drupal\opigno_learning_path
View source
class JoinService {

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * The entity form builder.
   *
   * @var \Drupal\Core\Entity\EntityFormBuilderInterface
   */
  protected $entityFormBuilder;

  /**
   * Constructs a new JoinService object.
   */
  public function __construct(AccountInterface $current_user, EntityFormBuilderInterface $entity_form_builder) {
    $this->currentUser = $current_user;
    $this->entityFormBuilder = $entity_form_builder;
  }

  /**
   * {@inheritdoc}
   */
  public function getForm($group) {
    $plugin = $group
      ->getGroupType()
      ->getContentPlugin('group_membership');

    // Pre-populate a group membership with the current user.
    $group_content = GroupContent::create([
      'type' => $plugin
        ->getContentTypeConfigId(),
      'gid' => $group
        ->id(),
      'entity_id' => $this->currentUser
        ->id(),
    ]);
    return $this->entityFormBuilder
      ->getForm($group_content, 'group-join');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JoinService::$currentUser protected property The current user.
JoinService::$entityFormBuilder protected property The entity form builder.
JoinService::getForm public function
JoinService::__construct public function Constructs a new JoinService object.