Ejemplo n.º 1
0
 /**
  * {@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}
  *
  * @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();
     }
 }
Ejemplo n.º 4
0
 /**
  * {@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');
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
Ejemplo n.º 6
0
 /**
  * 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']);
 }
 /**
  * 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 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);
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * {@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;
 }