You are here

class RegistrantFactory in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/RegistrantFactory.php \Drupal\rng\RegistrantFactory
  2. 3.x src/RegistrantFactory.php \Drupal\rng\RegistrantFactory

The registrant entity factory.

Hierarchy

Expanded class hierarchy of RegistrantFactory

1 string reference to 'RegistrantFactory'
rng.services.yml in ./rng.services.yml
rng.services.yml
1 service uses RegistrantFactory
rng.registrant.factory in ./rng.services.yml
Drupal\rng\RegistrantFactory

File

src/RegistrantFactory.php, line 11

Namespace

Drupal\rng
View 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

Namesort descending Modifiers Type Description Overrides
RegistrantFactory::$eventManager protected property The RNG event manager.
RegistrantFactory::$registrantStorage protected property Storage for registrant entities.
RegistrantFactory::createRegistrant public function Create a registrant entity based on available contexts. Overrides RegistrantFactoryInterface::createRegistrant
RegistrantFactory::__construct public function Constructs a new RegistrantFactory object.