You are here

public function Registration::addGroup in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Entity/Registration.php \Drupal\rng\Entity\Registration::addGroup()
  2. 3.x src/Entity/Registration.php \Drupal\rng\Entity\Registration::addGroup()

Add a group to the registration.

Parameters

\Drupal\rng\Entity\GroupInterface $group: The group to add.

Return value

\Drupal\rng\Entity\RegistrationInterface Returns registration for chaining.

Overrides RegistrationInterface::addGroup

1 call to Registration::addGroup()
Registration::preSave in src/Entity/Registration.php
Acts on an entity before the presave hook is invoked.

File

src/Entity/Registration.php, line 263

Class

Registration
Defines the registration entity class.

Namespace

Drupal\rng\Entity

Code

public function addGroup(GroupInterface $group) {

  // Do not add the group if it is already related.
  if (!in_array($group, $this
    ->getGroups())) {
    if ($group
      ->getEvent() != $this
      ->getEvent()) {
      throw new \Exception('Group and registration events do not match.');
    }
    $this->groups
      ->appendItem($group);
  }
  return $this;
}