public function RegistrantFactory::createRegistrant in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/RegistrantFactory.php \Drupal\rng\RegistrantFactory::createRegistrant()
- 3.x 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\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;
}