Skip to content
This repository was archived by the owner on Feb 23, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions rng.field.defaults.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ function rng_add_event_field_storage($field_name, $entity_type) {
);
break;

case EventManagerInterface::FIELD_WAIT_LIST:
$definition = [
'type' => 'boolean',
];
break;

case EventManagerInterface::FIELD_EMAIL_REPLY_TO:
$definition = array(
'type' => 'email',
Expand Down Expand Up @@ -127,6 +133,17 @@ function rng_event_field_config_definition($field_name) {
);
break;

case EventManagerInterface::FIELD_WAIT_LIST:
$definition = [
'label' => 'Allow a wait list',
'description' => t('Allow a waiting list for the event.'),
'settings' => [
'on_label' => t('Allow a waiting list for this event'),
'off_label' => t('Do not allow a waiting list for this event'),
],
];
break;

case EventManagerInterface::FIELD_EMAIL_REPLY_TO:
$definition = array(
'label' => t('Reply-to e-mail address'),
Expand Down Expand Up @@ -235,6 +252,12 @@ function rng_add_event_form_display_defaults(EntityFormDisplayInterface $form_di
));
break;

case EventManagerInterface::FIELD_WAIT_LIST:
$form_display->setComponent($field_name, [
'type' => 'boolean_checkbox',
]);
break;

case EventManagerInterface::FIELD_EMAIL_REPLY_TO:
$form_display->setComponent($field_name, array(
'type' => 'email_default',
Expand Down
12 changes: 12 additions & 0 deletions rng.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,15 @@ services:
arguments: ['@rng.event_route_context']
tags:
- { name: cache.context }
rng.registration_creation_subscriber:
class: Drupal\rng\EventSubscriber\RngRegistrationCreationSubscriber
arguments: ['@rng.event_manager']
tags:
- { name: event_subscriber }
rng.registration_waitlist_subscriber:
class: Drupal\rng\EventSubscriber\RegistrationWaitlistSubscriber
arguments:
- '@rng.event_manager'
- '@messenger'
tags:
- { name: event_subscriber }
76 changes: 66 additions & 10 deletions rng_views/extra/event.registrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,21 @@ display:
entity_type: registration
plugin_id: entity_operations
filters: { }
sorts: { }
sorts:
id:
id: id
table: registration_field_data
field: id
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
entity_type: registration
entity_field: id
plugin_id: standard
title: Registrations
header: { }
footer: { }
Expand Down Expand Up @@ -309,15 +323,56 @@ display:
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- user
- 'languages:language_content'
- 'languages:language_interface'
- url
cacheable: false
max-age: -1
tags: { }
attachment_1:
display_plugin: attachment
id: attachment_1
display_title: 'Waitlisted Registrations'
position: 2
display_options:
display_extenders:
views_advanced_routing_route:
route: ''
display_description: ''
title: 'Waitlisted Registrations'
defaults:
title: false
empty: false
pager:
type: none
options:
offset: 0
attachment_position: after
displays:
page_1: page_1
empty:
area_text_custom:
id: area_text_custom
table: views
field: area_text_custom
relationship: none
group_type: group
admin_label: ''
empty: true
tokenize: false
content: 'No waitlisted registrations.'
plugin_id: text_custom
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: 'My Page'
display_title: Registrations
position: 1
display_options:
display_extenders:
Expand All @@ -344,8 +399,9 @@ display:
display_description: ''
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- user
- 'languages:language_content'
- 'languages:language_interface'
- url
cacheable: false
max-age: -1
tags: { }
33 changes: 32 additions & 1 deletion rng_views/rng_views.module
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\views\Entity\View;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewExecutable;

/**
* Implements hook_form_BASE_FORM_ID_alter().
Expand Down Expand Up @@ -178,3 +179,33 @@ function rng_views_event_registrations(EntityTypeInterface $entity_type) {

return $view;
}

/**
* Implements hook_views_query_alter().
*/
function rng_views_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
/** @var \Drupal\rng\EventManager $event_manager */
$event_manager = \Drupal::service('rng.event_manager');
$event_types = $event_manager->getEventTypes();
foreach (array_keys($event_types) as $entity_type) {
if ($view->id() == "rng_registrations_$entity_type") {
/** @var \Drupal\Core\Routing\RouteMatchInterface $route_match */
$route_match = \Drupal::service('current_route_match');
/** @var \Drupal\Core\Entity\EntityInterface $event */
if ($event = $route_match->getParameter($entity_type)) {
if ($meta = $event_manager->getMeta($event)) {
// If we waitlist and have a registration limit, set some defaults.
if ($meta->allowWaitList() && $meta->getRegistrantsMaximum() > 0) {
if ($view->getDisplay()->display['id'] == 'page_1') {
$query->setLimit($meta->getRegistrantsMaximum());
}
if ($view->getDisplay()->display['id'] == 'attachment_1') {
$view->setOffset($meta->getRegistrantsMaximum());
}
}
}
}

}
}
}
37 changes: 13 additions & 24 deletions src/AccessControl/RegistrationAccessControlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\rng\Entity\RegistrationType;
use Drupal\rng\Event\RegistrationAccessEvent;
use Drupal\rng\Event\RegistrationEvents;
use Drupal\rng\RuleGrantsOperationTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityInterface;
Expand All @@ -27,12 +28,20 @@ class RegistrationAccessControlHandler extends EntityAccessControlHandler {
*/
protected $eventManager;

/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;

/**
* {@inheritdoc}
*/
public function __construct(EntityTypeInterface $entity_type) {
parent::__construct($entity_type);
$this->eventManager = \Drupal::service('rng.event_manager');
$this->eventDispatcher = \Drupal::service('event_dispatcher');
}

/**
Expand Down Expand Up @@ -89,29 +98,9 @@ public function createAccess($entity_bundle = NULL, AccountInterface $account =
$account = $this->prepareUser($account);

try {
$event_meta = $this->eventManager->getMeta($event);

// $entity_bundle is omitted for registration type list at
// $event_path/register
if ($entity_bundle && ($registration_type = RegistrationType::load($entity_bundle))) {
if (!$event_meta->registrationTypeIsValid($registration_type)) {
return $fail;
}
}
// There are no registration types configured.
elseif (!$event_meta->getRegistrationTypeIds()) {
return $fail;
}

if (!$event_meta->isAcceptingRegistrations()) {
return $fail;
}

if ($event_meta->remainingCapacity() == 0) {
return $fail;
}

if (!$event_meta->canRegisterProxyIdentities()) {
$event = new RegistrationAccessEvent($entity_bundle, $account, $context);
$this->eventDispatcher->dispatch(RegistrationEvents::REGISTRATION_CREATE_ACCESS, $event);
if (!$event->isAccessAllowed()) {
return $fail;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Entity/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class EventType extends ConfigEntityBase implements EventTypeInterface {
EventManagerInterface::FIELD_REGISTRATION_GROUPS,
EventManagerInterface::FIELD_STATUS,
EventManagerInterface::FIELD_CAPACITY,
EventManagerInterface::FIELD_WAIT_LIST,
EventManagerInterface::FIELD_EMAIL_REPLY_TO,
EventManagerInterface::FIELD_ALLOW_DUPLICATE_REGISTRANTS,
EventManagerInterface::FIELD_REGISTRATION_REGISTRANTS_MINIMUM,
Expand Down Expand Up @@ -386,6 +387,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
EventManagerInterface::FIELD_STATUS,
EventManagerInterface::FIELD_ALLOW_DUPLICATE_REGISTRANTS,
EventManagerInterface::FIELD_CAPACITY,
EventManagerInterface::FIELD_WAIT_LIST,
EventManagerInterface::FIELD_EMAIL_REPLY_TO,
EventManagerInterface::FIELD_REGISTRATION_TYPE,
EventManagerInterface::FIELD_REGISTRATION_GROUPS,
Expand Down
3 changes: 2 additions & 1 deletion src/Entity/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
* "edit" = "Drupal\rng\Form\RegistrationForm",
* "delete" = "Drupal\rng\Form\RegistrationDeleteForm",
* "registrants" = "Drupal\rng\Form\RegistrationRegistrantEditForm"
* }
* },
* "storage" = "Drupal\rng\RegistrationStorage",
* },
* bundle_entity_type = "registration_type",
* admin_permission = "administer registration entity",
Expand Down
Loading