/**
  * {@inheritdoc}
  *
  * @param \Drupal\rng\RegistrationTypeInterface|NULL $entity_bundle
  *   A registration type. Or NULL if it is a registration type listing.
  */
 public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = array(), $return_as_object = FALSE)
 {
     if (!isset($context['event'])) {
         throw new AccessException('Requires event context.');
     }
     $account = $this->prepareUser($account);
     if ($account->isAnonymous()) {
         return AccessResult::neutral();
     }
     try {
         $event_meta = $this->eventManager->getMeta($context['event']);
         // $entity_bundle is omitted for registration type list at
         // $event_path/register
         if ($entity_bundle && !$event_meta->registrationTypeIsValid($entity_bundle)) {
             return AccessResult::neutral();
         } elseif (!$event_meta->getRegistrationTypeIds()) {
             return AccessResult::neutral();
         }
         if (!$event_meta->isAcceptingRegistrations()) {
             return AccessResult::neutral();
         }
         if ($event_meta->remainingCapacity() == 0) {
             return AccessResult::neutral();
         }
         if (!$event_meta->countProxyIdentities()) {
             return AccessResult::neutral();
         }
         return AccessResult::allowed();
     } catch (InvalidEventException $e) {
         return AccessResult::neutral();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function load()
 {
     if (isset($this->event)) {
         return $this->eventManager->getMeta($this->event)->getRules(NULL, FALSE, NULL);
     }
     return parent::load();
 }
 /**
  * {@inheritdoc}
  */
 public function load()
 {
     if (isset($this->event)) {
         return $this->eventManager->getMeta($this->event)->getRegistrations();
     }
     return parent::load();
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     /** @var \Drupal\rng\EventTypeInterface $event_type */
     $event_type = $this->entity;
     if (!$event_type->isNew()) {
         $form['#title'] = $this->t('Edit event type %label configuration', array('%label' => $event_type->label()));
     }
     if ($event_type->isNew()) {
         $bundle_options = [];
         // Generate a list of fieldable bundles which are not events.
         foreach ($this->entityManager->getDefinitions() as $entity_type) {
             if ($entity_type->isSubclassOf('\\Drupal\\Core\\Entity\\ContentEntityInterface')) {
                 foreach ($this->entityManager->getBundleInfo($entity_type->id()) as $bundle => $bundle_info) {
                     if (!$this->eventManager->eventType($entity_type->id(), $bundle)) {
                         $bundle_options[(string) $entity_type->getLabel()][$entity_type->id() . '.' . $bundle] = $bundle_info['label'];
                     }
                 }
             }
         }
         if ($this->moduleHandler->moduleExists('node')) {
             $form['#attached']['library'][] = 'rng/rng.admin';
             $form['entity_type'] = ['#type' => 'radios', '#options' => NULL, '#title' => $this->t('Event entity type'), '#required' => TRUE];
             $form['entity_type']['node']['radio'] = ['#type' => 'radio', '#title' => $this->t('Create a new content type'), '#description' => $this->t('Create a content type to use as an event type.'), '#return_value' => "node", '#parents' => array('entity_type'), '#default_value' => 'node'];
             $form['entity_type']['existing']['radio'] = ['#type' => 'radio', '#title' => $this->t('Use existing bundle'), '#description' => $this->t('Use an existing entity/bundle combination.'), '#return_value' => "existing", '#parents' => array('entity_type'), '#default_value' => ''];
             $form['entity_type']['existing']['container'] = ['#type' => 'container', '#attributes' => ['class' => ['rng-radio-indent']]];
         }
         $form['entity_type']['existing']['container']['bundle'] = array('#type' => 'select', '#title' => $this->t('Bundle'), '#options' => $bundle_options, '#default_value' => $event_type->id(), '#disabled' => !$event_type->isNew(), '#empty_option' => $bundle_options ? NULL : t('No Bundles Available'));
     }
     $form['settings'] = array('#type' => 'fieldset', '#title' => $this->t('Settings'));
     // Mirror permission.
     $form['access']['mirror_update'] = array('#group' => 'settings', '#type' => 'checkbox', '#title' => t('Mirror manage registrations with update permission'), '#description' => t('Allow users to <strong>manage registrations</strong> if they have <strong>update</strong> permission on an event entity.'), '#default_value' => (bool) ($event_type->getEventManageOperation() !== NULL ? $event_type->getEventManageOperation() : TRUE));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $this->derivatives = [];
     /** @var \Drupal\rng\Entity\EventType[] $event_types */
     foreach ($this->eventManager->getEventTypes() as $entity_type => $event_types) {
         $cache_tags = $this->entityManager->getDefinition($entity_type)->getListCacheTags();
         foreach ($event_types as $event_type) {
             $cache_tags = Cache::mergeTags($cache_tags, $event_type->getCacheTags());
         }
         // Only need one set of tasks task per entity type.
         if ($this->routeProvider->getRouteByName("entity.{$entity_type}.canonical")) {
             $event_default = "rng.event.{$entity_type}.event.default";
             $this->derivatives[$event_default] = array('title' => t('Event'), 'base_route' => "entity.{$entity_type}.canonical", 'route_name' => "rng.event.{$entity_type}.event", 'weight' => 30, 'cache_tags' => $cache_tags);
             $this->derivatives["rng.event.{$entity_type}.event.settings"] = array('title' => t('Settings'), 'route_name' => $this->derivatives[$event_default]['route_name'], 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 10, 'cache_tags' => $cache_tags);
             $this->derivatives["rng.event.{$entity_type}.event.access"] = array('title' => t('Access'), 'route_name' => "rng.event.{$entity_type}.access", 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 20, 'cache_tags' => $cache_tags);
             $this->derivatives["rng.event.{$entity_type}.event.messages"] = array('title' => t('Messages'), 'route_name' => "rng.event.{$entity_type}.messages", 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 30, 'cache_tags' => $cache_tags);
             $this->derivatives["rng.event.{$entity_type}.event.group.list"] = array('title' => t('Groups'), 'route_name' => "rng.event.{$entity_type}.group.list", 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 40, 'cache_tags' => $cache_tags);
             $this->derivatives["rng.event.{$entity_type}.register.type_list"] = array('route_name' => "rng.event.{$entity_type}.register.type_list", 'base_route' => "entity.{$entity_type}.canonical", 'title' => t('Register'), 'weight' => 40, 'cache_tags' => $cache_tags);
         }
     }
     foreach ($this->derivatives as &$entry) {
         $entry += $base_plugin_definition;
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
 /**
  * Checks that an entity is an event type.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     if ($event = $route->getDefault('event')) {
         $event = $route_match->getParameter($event);
         if ($event instanceof EntityInterface) {
             return AccessResult::allowedIf($this->eventManager->isEvent($event));
         }
     }
     return AccessResult::neutral();
 }
 /**
  * {@inheritdoc}
  */
 public function getTitle()
 {
     $route = $this->routeProvider->getRouteByName($this->getRouteName());
     $param = $route->getDefault('event');
     if ($event = $this->currentRoute->getParameter($param)) {
         if ($this->eventManager->getMeta($event)->isDefaultRules('rng_event.register')) {
             return $this->t('Customize access rules');
         } else {
             return $this->t('Reset access rules to site default');
         }
     }
 }
 /**
  * Constructs a new RegisterIdentityContactSelection object.
  *
  * {@inheritdoc}
  *
  * @param \Drupal\rng\EventManagerInterface $event_manager
  *   The RNG event manager.
  * @param \Drupal\Core\Condition\ConditionManager $condition_manager
  *   The condition plugin manager.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user, Connection $connection, EventManagerInterface $event_manager, ConditionManager $condition_manager)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_manager, $module_handler, $current_user, $connection);
     if (isset($this->configuration['handler_settings']['event_entity_type'], $this->configuration['handler_settings']['event_entity_id'])) {
         $event = $this->entityManager->getStorage($this->configuration['handler_settings']['event_entity_type'])->load($this->configuration['handler_settings']['event_entity_id']);
         $this->eventMeta = $event_manager->getMeta($event);
     } else {
         throw new \Exception('RNG selection handler requires event context.');
     }
     $this->conditionManager = $condition_manager;
     $this->entityType = $this->entityManager->getDefinition($this->configuration['target_type']);
 }
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     $event_types = $this->eventManager->getEventTypes();
     foreach (array_keys($event_types) as $entity_type) {
         $definition = $this->entityManager->getDefinition($entity_type);
         if ($canonical_path = $definition->getLinkTemplate('canonical')) {
             $manage_requirements = ['_entity_access' => $entity_type . '.manage event', '_entity_is_event' => 'TRUE', '_permission' => 'debug rng'];
             $options = [];
             $options['parameters'][$entity_type]['type'] = 'entity:' . $entity_type;
             // Rules.
             $route = new Route($canonical_path . '/event/rules', array('_controller' => '\\Drupal\\rng_debug\\Controller\\DebugController::listing', '_title' => 'Rules', 'event' => $entity_type), $manage_requirements, $options);
             $collection->add("rng.event.{$entity_type}.rules", $route);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $this->derivatives = [];
     $event_types = $this->eventManager->getEventTypes();
     foreach (array_keys($event_types) as $entity_type) {
         // Only need one set of tasks task per entity type.
         if ($this->routeProvider->getRouteByName("entity.{$entity_type}.canonical")) {
             $event_default = "rng.event.{$entity_type}.event.default";
             $this->derivatives["rng.event.{$entity_type}.event.rules"] = array('title' => t('Rules'), 'route_name' => "rng.event.{$entity_type}.rules", 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 20);
         }
     }
     foreach ($this->derivatives as &$entry) {
         $entry += $base_plugin_definition;
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
 /**
  * Get a list of rules.
  *
  * @param \Drupal\Core\Entity\EntityInterface $event
  *   An event entity.
  *
  * @return \Drupal\rng\RuleInterface[]
  *   An array of rng_rule entities keyed by rule ID.
  */
 protected function getCommunicationRules(EntityInterface $event)
 {
     // List of communication related action plugin ids.
     $communication_actions = ['rng_courier_message'];
     $rules = [];
     $rules_all = $this->eventManager->getMeta($event)->getRules(NULL, FALSE, NULL);
     foreach ($rules_all as $rid => $rule) {
         foreach ($rule->getActions() as $action) {
             $action_id = $action->getPluginId();
             if (in_array($action_id, $communication_actions)) {
                 $rules[$rid] = $rule;
                 continue 2;
             }
         }
     }
     return $rules;
 }
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $this->derivatives = [];
     /** @var \Drupal\rng\Entity\EventType[] $event_types */
     foreach ($this->eventManager->getEventTypes() as $entity_type => $event_types) {
         $cache_tags = $this->entityManager->getDefinition($entity_type)->getListCacheTags();
         foreach ($event_types as $event_type) {
             $cache_tags = Cache::mergeTags($cache_tags, $event_type->getCacheTags());
         }
         // Only need one set of actions per entity type.
         $this->derivatives["rng.event.{$entity_type}.event.access.reset"] = array('title' => $this->t('Reset/customize access rules'), 'route_name' => "rng.event.{$entity_type}.access.reset", 'class' => '\\Drupal\\rng\\Plugin\\Menu\\LocalAction\\ResetAccessRules', 'appears_on' => array("rng.event.{$entity_type}.access"), 'cache_tags' => $cache_tags);
         $this->derivatives["rng.event.{$entity_type}.event.message.add"] = array('title' => $this->t('Add message'), 'route_name' => "rng.event.{$entity_type}.messages.add", 'appears_on' => array("rng.event.{$entity_type}.messages"), 'cache_tags' => $cache_tags);
         $this->derivatives["rng.event.{$entity_type}.event.group.add"] = array('title' => $this->t('Add group'), 'route_name' => "rng.event.{$entity_type}.group.add", 'appears_on' => array("rng.event.{$entity_type}.group.list"), 'cache_tags' => $cache_tags);
     }
     foreach ($this->derivatives as &$entry) {
         $entry += $base_plugin_definition;
     }
     return $this->derivatives;
 }
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     $event_types = $this->eventManager->getEventTypes();
     foreach (array_keys($event_types) as $entity_type) {
         $definition = $this->entityManager->getDefinition($entity_type);
         if ($canonical_path = $definition->getLinkTemplate('canonical')) {
             $manage_requirements = ['_entity_access' => $entity_type . '.manage event', '_entity_is_event' => 'TRUE'];
             $options = [];
             // Option will invoke EntityConverter ParamConverter to upcast the
             // entity in $canonical_path.
             $options['parameters'][$entity_type]['type'] = 'entity:' . $entity_type;
             // Manage Event.
             $route = new Route($canonical_path . '/event', array('_form' => '\\Drupal\\rng\\Form\\EventSettingsForm', '_title' => 'Manage event', 'event' => $entity_type), $manage_requirements, $options);
             $collection->add("rng.event.{$entity_type}.event", $route);
             // Access.
             $route = new Route($canonical_path . '/event/access', array('_controller' => '\\Drupal\\rng\\Controller\\EventController::listing_access', '_title' => 'Access', 'event' => $entity_type), $manage_requirements, $options);
             $collection->add("rng.event.{$entity_type}.access", $route);
             // Reset access to default.
             $route = new Route($canonical_path . '/event/access/reset', array('_form' => '\\Drupal\\rng\\Form\\EventAccessResetForm', '_title' => 'Reset access to default', 'event' => $entity_type), $manage_requirements, $options);
             $collection->add("rng.event.{$entity_type}.access.reset", $route);
             // Messages.
             $route = new Route($canonical_path . '/event/messages', array('_form' => '\\Drupal\\rng\\Form\\MessageListForm', '_title' => 'Messages', 'event' => $entity_type), $manage_requirements, $options);
             $collection->add("rng.event.{$entity_type}.messages", $route);
             // Message add.
             $route = new Route($canonical_path . '/event/messages/add', array('_form' => '\\Drupal\\rng\\Form\\MessageActionForm', '_title' => 'Add message', 'event' => $entity_type), $manage_requirements, $options);
             $collection->add("rng.event.{$entity_type}.messages.add", $route);
             // Group list.
             $route = new Route($canonical_path . '/event/groups', array('_controller' => '\\Drupal\\rng\\Controller\\GroupController::listing', '_title' => 'Groups', 'event' => $entity_type), $manage_requirements, $options);
             $collection->add("rng.event.{$entity_type}.group.list", $route);
             // Group add.
             $route = new Route($canonical_path . '/event/groups/add', array('_controller' => '\\Drupal\\rng\\Controller\\GroupController::GroupAdd', '_title' => 'Add group', 'event' => $entity_type), $manage_requirements, $options);
             $collection->add("rng.event.{$entity_type}.group.add", $route);
             // Register.
             $route = new Route($canonical_path . '/register', array('_controller' => '\\Drupal\\rng\\Controller\\RegistrationController::RegistrationAddPage', '_title' => 'Register', 'event' => $entity_type), array('_registration_add_access' => 'TRUE'), $options);
             $collection->add("rng.event.{$entity_type}.register.type_list", $route);
             // Register w/ Registration Type.
             $options_register = $options;
             $options_register['parameters']['registration_type']['type'] = 'entity:registration_type';
             $route = new Route($canonical_path . '/register/{registration_type}', array('_controller' => '\\Drupal\\rng\\Controller\\RegistrationController::RegistrationAdd', '_title_callback' => '\\Drupal\\rng\\Controller\\RegistrationController::addPageTitle', 'event' => $entity_type), array('_registration_add_access' => 'TRUE'), $options_register);
             $collection->add("rng.event.{$entity_type}.register", $route);
         }
     }
 }
 /**
  * Generates a list of registration types for an event.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The matched route.
  *
  * @param string $event
  *   The parameter to find the event entity.
  *
  * @return array A registration form.
  */
 public function RegistrationAddPage(RouteMatchInterface $route_match, $event)
 {
     $event_entity = $route_match->getParameter($event);
     $render = [];
     $registration_types = $this->eventManager->getMeta($event_entity)->getRegistrationTypes();
     if (count($registration_types) == 1) {
         $registration_type = array_shift($registration_types);
         return $this->redirect('rng.event.' . $event . '.register', [$event => $event_entity->id(), 'registration_type' => $registration_type->id()]);
     } else {
         $render['links'] = array('#title' => $this->t('Select @entity_type', ['@entity_type' => \Drupal::entityManager()->getDefinition('registration_type')->getLabel()]), '#theme' => 'item_list', '#items' => []);
     }
     foreach ($registration_types as $registration_type) {
         $item = [];
         $url = new Url('rng.event.' . $event . '.register', [$event => $event_entity->id(), 'registration_type' => $registration_type->id()]);
         $item[] = ['#type' => 'link', '#title' => $registration_type->label(), '#url' => $url, '#prefix' => '<h3>', '#suffix' => '</h3>'];
         if (!empty($registration_type->description)) {
             $item[] = ['#markup' => $registration_type->description];
         }
         $render['links']['#items'][] = $item;
     }
     return $render;
 }
 /**
  * Sends the message.
  *
  * @param array $context
  *   An associative array defining context.
  *   - \Drupal\rng\RegistrationInterface[] registrations: An array of
  *     registrations to send the message.
  */
 public function execute($context = NULL)
 {
     if ($collection_original = $this->getTemplateCollection()) {
         foreach ($context['registrations'] as $registration) {
             $options = [];
             /** @var \Drupal\rng\RegistrationInterface $registration */
             if (($event = $registration->getEvent()) instanceof EntityInterface) {
                 $event_meta = $this->eventManager->getMeta($event);
                 $options['channels']['courier_email']['reply_to'] = $event_meta->getReplyTo();
                 $collection_original->setTokenValue($event->getEntityTypeId(), $event);
             }
             $collection = clone $collection_original;
             $collection->setTokenValue('registration', $registration);
             foreach ($registration->getRegistrants() as $registrant) {
                 $identity = $registrant->getIdentity();
                 $this->courierManager->sendMessage($collection, $identity, $options);
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $current_user = $this->currentUser();
     $registration = $this->getEntity();
     $event = $registration->getEvent();
     if (!$registration->isNew()) {
         $form['#title'] = $this->t('Edit Registration', array('%event_label' => $event->label(), '%event_id' => $event->id(), '%registration_id' => $registration->id()));
     }
     $form = parent::form($form, $form_state, $registration);
     if ($registration->isNew()) {
         $form['identity_information'] = ['#type' => 'details', '#title' => $this->t('Identity'), '#description' => $this->t('Select an identity to associate with this registration.'), '#open' => TRUE];
         $form['identity_information']['identity'] = ['#type' => 'radios', '#options' => NULL, '#title' => $this->t('Identity'), '#required' => TRUE];
         $self = FALSE;
         $event_meta = $this->eventManager->getMeta($event);
         // Create a register radio option for current user.
         // list of entity reference field types, ordered by radio default priority.
         $entity_types = $event_meta->getIdentityTypes();
         // Radio order is alphabetical. (ex: self).
         $sorted = $entity_types;
         ksort($sorted);
         foreach ($sorted as $entity_type_id) {
             $options = ['target_type' => $entity_type_id, 'handler' => 'rng_register', 'handler_settings' => ['event_entity_type' => $event->getEntityTypeId(), 'event_entity_id' => $event->id()]];
             /* @var $selection \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface */
             $selection = $this->selectionManager->getInstance($options);
             $count = $selection->countReferenceableEntities();
             if ($entity_type_id == 'user') {
                 // If duplicate registrants is allowed || user is not already a registrant.
                 if ($event_meta->identitiesCanRegister('user', [$current_user->id()])) {
                     $self = TRUE;
                     $count--;
                 }
             }
             if ($count > 0) {
                 $entity_type = $this->entityManager->getDefinition($entity_type_id);
                 $form['identity_information']['identity'][$entity_type_id] = ['#prefix' => '<div class="form-item container-inline">', '#suffix' => '</div>'];
                 $form['identity_information']['identity'][$entity_type_id]['radio'] = ['#type' => 'radio', '#title' => $entity_type->getLabel(), '#return_value' => "{$entity_type_id}:*", '#parents' => array('identity'), '#default_value' => ''];
                 $form['identity_information']['identity'][$entity_type_id]['autocomplete'] = ['#type' => 'entity_autocomplete', '#title' => $entity_type->getLabel(), '#title_display' => 'invisible', '#target_type' => $entity_type_id, '#selection_handler' => 'rng_register', '#selection_settings' => ['event_entity_type' => $event->getEntityTypeId(), 'event_entity_id' => $event->id()], '#tags' => FALSE, '#parents' => array('entity', $entity_type_id)];
                 // Add link: The 'add' link is something invented by RNG, it is not a
                 // standard link.
                 // @todo: replace with add and reference ajax popup + form.
                 if ($add_link = $entity_type->getLinkTemplate('add-form')) {
                     $form['identity_information']['identity'][$entity_type_id]['add'] = ['#type' => 'link', '#title' => $this->t('Add @entity_type', ['@entity_type' => $entity_type->getLabel()]), '#url' => Url::fromUserInput($entity_type->getLinkTemplate('add-form')), '#prefix' => '[', '#suffix' => ']'];
                 }
             }
         }
         if ($self) {
             $form['identity_information']['identity']['self'] = ['#type' => 'radio', '#title' => t('My account: %username', array('%username' => $current_user->getUsername())), '#return_value' => 'user:'******'#parents' => array('identity'), '#default_value' => TRUE, '#weight' => -100];
         } else {
             // Self will always be default, if it exists.
             // Otherwise apply default based on $entity_types array order.
             foreach ($entity_types as $entity_type_id) {
                 // Not all $entity_types are created, depends if there are any
                 // referenceable entities.
                 if (isset($form['identity_information']['identity'][$entity_type_id])) {
                     $form['identity_information']['identity'][$entity_type_id]['radio']['#default_value'] = TRUE;
                     break;
                 }
             }
         }
         $form['identity_information']['redirect_identities'] = ['#type' => 'checkbox', '#title' => $this->t('Add additional identities after saving.'), '#default_value' => FALSE, '#access' => FALSE];
     } else {
         $form['revision_information'] = array('#type' => 'details', '#title' => $this->t('Revisions'), '#optional' => TRUE, '#open' => $current_user->hasPermission('administer rng'));
         $form['revision'] = array('#type' => 'checkbox', '#title' => $this->t('Create new revision'), '#description' => $this->t('Revisions record changes between saves.'), '#default_value' => FALSE, '#access' => $current_user->hasPermission('administer rng'), '#group' => 'revision_information');
     }
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $event = NULL)
 {
     $this->event = clone $route_match->getParameter($event);
     $this->eventMeta = $this->eventManager->getMeta($this->event);
     return parent::buildForm($form, $form_state);
 }
 /**
  * Displays a list of actions which are related to registration access on an
  * event.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The current route.
  * @param string $event
  *   The parameter to find the event entity.
  *
  * @return array
  *   A render array.
  */
 public function listing_access(RouteMatchInterface $route_match, $event)
 {
     $event = $route_match->getParameter($event);
     $destination = $this->redirectDestination->getAsArray();
     $event_meta = $this->eventManager->getMeta($event);
     $trigger = 'rng_event.register';
     $build = [];
     $build['description'] = ['#prefix' => '<p>', '#markup' => $this->t('The following rules determine who is eligible to register or perform an operation on a registration.<br />Access is granted if all conditions for a rule evaluate as true.'), '#suffix' => '</p>'];
     $rows = [];
     // Header.
     $rows[0] = [['header' => TRUE, 'rowspan' => 2, 'data' => $this->t('Rule')], ['header' => TRUE, 'rowspan' => 2, 'data' => $this->t('Component')], ['header' => TRUE, 'rowspan' => 2, 'data' => $this->t('Scope')], ['header' => TRUE, 'rowspan' => 1, 'data' => $this->t('Operations'), 'colspan' => 4]];
     if (!$event_meta->isDefaultRules($trigger)) {
         $rows[0][] = ['header' => TRUE, 'rowspan' => 2, 'data' => ''];
     }
     $operations = ['create' => $this->t('Create'), 'view' => $this->t('View'), 'update' => $this->t('Update'), 'delete' => $this->t('Delete')];
     foreach ($operations as $operation) {
         $rows['operations'][] = ['header' => TRUE, 'data' => $operation];
     }
     $i = 0;
     $rules = $event_meta->getRules($trigger, TRUE);
     foreach ($rules as $rule) {
         $i++;
         $scope_all = FALSE;
         $supports_create = 0;
         $condition_context = [];
         // Conditions.
         $k = 0;
         $row = [];
         $row['rule'] = ['header' => FALSE, 'data' => $this->t('@row.', ['@row' => $i]), 'rowspan' => count($rule->getConditions()) + 1];
         foreach ($rule->getConditions() as $condition_storage) {
             $k++;
             $row[] = ['header' => TRUE, 'data' => $this->t('Condition #@condition', ['@condition' => $k])];
             $condition = $condition_storage->createInstance();
             $condition_context += array_keys($condition->getContextDefinitions());
             $scope_all = !in_array('registration', $condition_context) || in_array('event', $condition_context);
             if (isset($row['rule']['rowspan']) && $scope_all) {
                 $row['rule']['rowspan']++;
             }
             if ($condition instanceof RNGConditionInterface) {
                 $supports_create++;
             }
             $row[] = ['colspan' => 5, 'data' => $condition->summary()];
             if (!$event_meta->isDefaultRules($trigger)) {
                 $row['condition_operations']['data'] = ['#type' => 'operations'];
                 if ($condition_storage->access('edit')) {
                     $row['condition_operations']['data']['#links']['edit'] = ['title' => t('Edit'), 'url' => $condition_storage->urlInfo('edit-form'), 'query' => $destination];
                 }
             }
             $rows[] = ['data' => $row, 'no_striping' => TRUE];
             $row = [];
         }
         // Actions.
         foreach ($rule->getActions() as $action_storage) {
             $row = [];
             $row[] = ['header' => TRUE, 'data' => $this->t('Grants operations'), 'rowspan' => $scope_all ? 2 : 1];
             // Scope: warn user actions apply to all registrations.
             $row[]['data'] = $scope_all ? $this->t('All registrations.') : $this->t('Single registration');
             // Operations granted.
             $config = $action_storage->getConfiguration();
             foreach ($operations as $op => $t) {
                 $message = !empty($config['operations'][$op]) ? $t : '-';
                 $row['operation_' . $op] = ['data' => $op == 'create' && $supports_create != count($rule->getConditions()) ? $this->t('<em>N/A</em>') : $message];
             }
             if (!$event_meta->isDefaultRules($trigger)) {
                 $links = [];
                 if ($action_storage->access('edit')) {
                     $links['edit'] = ['title' => t('Edit'), 'url' => $action_storage->urlInfo('edit-form'), 'query' => $destination];
                 }
                 $row[] = ['data' => ['#type' => 'operations', '#links' => $links], 'rowspan' => $scope_all ? 2 : 1];
             }
             $rows[] = $row;
             if ($scope_all) {
                 $rows[] = [['data' => $this->t('<strong>Warning:</strong> selecting view, update, or delete grants access to any registration on this event.'), 'colspan' => 5]];
             }
         }
     }
     $build[] = ['#type' => 'table', '#header' => [], '#rows' => $rows, '#empty' => $this->t('No access rules.')];
     return $build;
 }