You are here

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

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

Shortcut to add a registrant entity.

Take care to ensure the identity is not already on the registration.

Parameters

\Drupal\Core\Entity\EntityInterface $identity: The identity to add.

Return value

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

Overrides RegistrationInterface::addIdentity

File

src/Entity/Registration.php, line 241

Class

Registration
Defines the registration entity class.

Namespace

Drupal\rng\Entity

Code

public function addIdentity(EntityInterface $identity) {
  if ($this
    ->hasIdentity($identity)) {

    // Identity already exists on this registration.
    throw new \Exception('Duplicate identity on registration');
  }
  if (!$this
    ->canAddRegistrants()) {
    throw new MaxRegistrantsExceededException('Cannot add another registrant to this registration.');
  }
  $this->identities_unsaved[] = $identity;
  return $this;
}