class RegistrantFactory in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/RegistrantFactory.php \Drupal\rng\RegistrantFactory
- 3.x src/RegistrantFactory.php \Drupal\rng\RegistrantFactory
The registrant entity factory.
Hierarchy
- class \Drupal\rng\RegistrantFactory implements RegistrantFactoryInterface
Expanded class hierarchy of RegistrantFactory
1 string reference to 'RegistrantFactory'
1 service uses RegistrantFactory
File
- src/
RegistrantFactory.php, line 11
Namespace
Drupal\rngView source
class RegistrantFactory implements RegistrantFactoryInterface {
/**
* Storage for registrant entities.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $registrantStorage;
/**
* The RNG event manager.
*
* @var \Drupal\rng\EventManagerInterface
*/
protected $eventManager;
/**
* Constructs a new RegistrantFactory object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\rng\EventManagerInterface $event_manager
* The RNG event manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EventManagerInterface $event_manager) {
$this->registrantStorage = $entity_type_manager
->getStorage('registrant');
$this->eventManager = $event_manager;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RegistrantFactory:: |
protected | property | The RNG event manager. | |
RegistrantFactory:: |
protected | property | Storage for registrant entities. | |
RegistrantFactory:: |
public | function |
Create a registrant entity based on available contexts. Overrides RegistrantFactoryInterface:: |
|
RegistrantFactory:: |
public | function | Constructs a new RegistrantFactory object. |