public function RegistrantFactory::createRegistrant in RNG - Events and Registrations 3.x
Same name and namespace in other branches
- 8.2 src/RegistrantFactory.php \Drupal\rng\RegistrantFactory::createRegistrant()
- 8 src/RegistrantFactory.php \Drupal\rng\RegistrantFactory::createRegistrant()
Create a registrant entity based on available contexts.
Parameters
array $context: An array of contexts, including:
- event (required): An event entity.
- identity_entity_type: Entity type ID of the identity.
- identity_bundle: Bundle of the identity.
- identity: A identity entity.
Return value
\Drupal\rng\Entity\RegistrantInterface A registrant entity.
Throws
\InvalidArgumentException If missing required context.
\Exception Miscellaneous errors, including missing configuration on event type.
Overrides RegistrantFactoryInterface::createRegistrant
File
- src/
RegistrantFactory.php, line 44
Class
- RegistrantFactory
- The registrant entity factory.
Namespace
Drupal\rngCode
public function createRegistrant(array $context) {
if (!isset($context['event']) || !$context['event'] instanceof EntityInterface) {
throw new \InvalidArgumentException('Registrant factory missing event context.');
}
$event = $context['event'];
$event_meta = $this->eventManager
->getMeta($event);
$event_type = $event_meta
->getEventType();
$values = [
'type' => $event_type
->getDefaultRegistrantType(),
];
$registrant = $this->registrantStorage
->create($values);
return $registrant;
}