Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D8 2211 #265

Open
wants to merge 22 commits into
base: 3.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5794ff2
access_misc: d8-2211
protitude Dec 10, 2024
52b9596
access_misc: event registration customizations d8-2211
protitude Dec 13, 2024
023b8eb
access_misc: fixes - invalidate events view cache d8-2211
protitude Dec 13, 2024
7485cf7
access_misc: update route registration perms d8-2211
protitude Dec 14, 2024
3d88b47
access_misc: hide register button field d8-2211
protitude Dec 17, 2024
b11f879
access_misc: events form
protitude Dec 19, 2024
f08a34d
Add another speaker widget text
protitude Dec 24, 2024
e72431c
Deny -> Approve
protitude Dec 30, 2024
dc4647d
access_misc: d8-2211
protitude Jan 9, 2025
06e6355
access_misc: pull in other perms de-2211
protitude Jan 10, 2025
b30204a
access_misc: move tags title - remove reg description d8-2211
protitude Jan 10, 2025
2c41f7f
access_misc: adding in initial email for registration
protitude Jan 10, 2025
eaa11fd
access_misc: uncomment class d8-2211
protitude Jan 10, 2025
5ee643b
access_misc: fix email
protitude Jan 10, 2025
66f7d3d
access_misc: fix email variable
protitude Jan 10, 2025
5669028
Adding email for approval
protitude Jan 12, 2025
4c3eb0a
access_misc: fix email d8-2211
protitude Jan 12, 2025
7b1e6da
access_misc: fix time da-2211
protitude Jan 12, 2025
505ae69
access_misc: add waitlist email d8-2211
protitude Jan 13, 2025
52425a2
access_misc: fix waitlist variable d8-2211
protitude Jan 13, 2025
11a996d
access_misc: add full contact sentence if exists d8-2211
protitude Jan 13, 2025
af6507b
access_misc: add space d8-2211
protitude Jan 13, 2025
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
222 changes: 220 additions & 2 deletions modules/access_misc/access_misc.module
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use Drupal\user\Entity\User;
use Drupal\views\ViewExecutable;
use Drupal\Component\Utility\Xss;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Url;

/**
Expand Down Expand Up @@ -79,6 +80,15 @@ function access_misc_user_login(UserInterface $account) {
}
}

/**
* Implements hook_entity_type_build().
*/
function access_misc_entity_type_build(array $entity_types) {
if (isset($entity_types['registrant'])) {
$entity_types['registrant']->setHandlerClass('access', 'Drupal\access_misc\AccessRegistrantAccessControlHandler');
}
}

/**
* Implements hook_views_pre_render().
*/
Expand All @@ -99,6 +109,39 @@ function access_misc_views_pre_render(ViewExecutable $view) {
}
}

/**
* Implements hook_entity_view_alter().
*/
function access_misc_entity_view_alter(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) {
if ($entity->getEntityTypeId() == 'eventinstance') {
$build['virtual_meeting_link']['#access'] = TRUE;
$entity_id = $entity->id();
$series = $entity->getEventSeries();
$registration_status = $series->get('event_registration')->getValue()[0]['registration'];

// Get current user id.
$current_user = \Drupal::currentUser();
$uid = $current_user->id();

if ($registration_status) {
// Entity Query 'registrant' to get all registrants for the event instance.
$query = \Drupal::entityQuery('registrant')
->condition('eventinstance_id', $entity_id)
->condition('status', 1)
->condition('user_id', $uid)
->accessCheck(TRUE);
$registrants = $query->execute();

$registrants = empty($registrants) ? TRUE : FALSE;


if ($registrants) {
$build['virtual_meeting_link']['#access'] = FALSE;
}
}
}
}

/**
* Implements hook_views_post_render().
*
Expand Down Expand Up @@ -181,6 +224,49 @@ function access_misc_preprocess_views_view_field(&$variables) {
$view = $variables['view'];
$field = $variables['field'];

// Overwrite affinity_groups into /people page on the
// /admin/structure/views/view/events_facet/edit/page_1 view.
if ($view->id() == 'events_facet' && $field->options['id'] == 'id_1') {
$event_instance_id = $variables['output']->__toString();
$event_instance = \Drupal::entityTypeManager()->getStorage('eventinstance')->load($event_instance_id);
$series = $event_instance->getEventSeries();
$link = $series->get('field_event_virtual_meeting_link')->getValue();

$variables['output'] = "";

if ($link) {
$registration_status = $series->get('event_registration')->getValue()[0]['registration'];

// Get current user id.
$current_user = \Drupal::currentUser();
$uid = $current_user->id();

$link_url = $link[0]['uri'];

$meeting_link = "<a href='$link_url' class='btn-sm btn-small btn-secondary-outline py-0 px-4 btn btn-md-teal ms-auto'> Join meeting</a>";

if ($registration_status) {
// Entity Query 'registrant' to get all registrants for the event instance.
$query = \Drupal::entityQuery('registrant')
->condition('eventinstance_id', $event_instance_id)
->condition('status', 1)
->condition('user_id', $uid)
->accessCheck(TRUE);
$registrants = $query->execute();

$registrants = empty($registrants) ? FALSE : TRUE;


if ($registrants) {
$variables['output'] = Markup::create($meeting_link);
}
} else {
// Show link when registration is not required.
$variables['output'] = Markup::create($meeting_link);
}
}
}

// Overwrite affinity_groups into /people page on the
// /admin/structure/views/view/nect_cc_people/edit/page_1 view.
if ($view->id() == 'nect_cc_people' && $view->current_display == 'page_1' && $field->options['id'] == 'uid_1') {
Expand Down Expand Up @@ -331,16 +417,89 @@ function access_misc_datalayer_alter(&$data_layer) {
* Implements hook_form_alter().
*/
function access_misc_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'registrant_default_add_form' || $form_id == 'registrant_default_edit_form') {
// Email registered user.
$form['actions']['submit']['#submit'][] = 'access_misc_registrant_email_submit';

// Get current user.
$current_user = \Drupal::currentUser();
$roles = $current_user->getRoles();

if (!in_array('administrator', $roles)) {
// Get current user field 'field_user_first_name'.
$user = User::load($current_user->id());
$first_name = $user->get('field_user_first_name')->value;
$last_name = $user->get('field_user_last_name')->value;
$email = $user->getEmail();
$form['field_first_name']['widget'][0]['value']['#default_value'] = $first_name;
$form['field_first_name']['widget'][0]['value']['#access'] = FALSE;
$form['field_last_name']['widget'][0]['value']['#default_value'] = $last_name;
$form['field_last_name']['widget'][0]['value']['#access'] = FALSE;
$form['email']['widget'][0]['value']['#default_value'] = $email;
$form['email']['widget'][0]['value']['#access'] = FALSE;
$form['user_id']['widget'][0]['#access'] = FALSE;

// Check if user is registered and redirect back to event if so.
$uri = \Drupal::request()->getRequestUri();
$uri = explode('/', $uri);
$eventinstance_id = $uri[2];
$entity_query = \Drupal::entityQuery('registrant')
->condition('eventinstance_id', $eventinstance_id)
->condition('user_id', $current_user->id())
->accessCheck(FALSE);
$registrant_status = $entity_query->execute();

if ($registrant_status) {
$redirect = new RedirectResponse('/events/' . $eventinstance_id);
$redirect->send();
\Drupal::messenger()->addMessage(t('You are already registered for this event.'));
}

// Add submit handler to registrant form to invalidate cache on Events
// Facet view.
$form['actions']['submit']['#submit'][] = 'access_misc_registrant_submit';
}
}
if ( ($form_id == 'registrant_default_add_form' || $form_id == 'registrant_default_edit_form') && in_array('administrator', $roles)) {
$form['field_first_name']['widget'][0]['value']['#access'] = TRUE;
$form['field_last_name']['widget'][0]['value']['#access'] = TRUE;
$form['email']['widget'][0]['value']['#access'] = TRUE;
$form['user_id']['widget'][0]['#access'] = TRUE;

if ($form_id == 'registrant_default_add_form') {
// Get current user.
$current_user = \Drupal::currentUser();
// Get current user field 'field_user_first_name'.
$user = User::load($current_user->id());
$first_name = $user->get('field_user_first_name')->value;
$last_name = $user->get('field_user_last_name')->value;
$email = $user->getEmail();

$form['field_first_name']['widget'][0]['value']['#default_value'] = $first_name;
$form['field_last_name']['widget'][0]['value']['#default_value'] = $last_name;
$form['email']['widget'][0]['value']['#default_value'] = $email;
}

// Add submit handler to registrant form to invalidate cache on Events
// Facet view.
$form['actions']['submit']['#submit'][] = 'access_misc_registrant_submit';
}

// Custom tags on /events/add
if ($form_id == 'eventseries_default_add_form' || $form_id == 'eventseries_default_edit_form') {
$form['event_registration']['widget'][0]['#description'] = "";
$form['consecutive_recurring_date'] = [];
$form['field_tags_replace'] = [
'#type' => 'container',
'#attributes' => [
'id' => 'field-tags-replace',
'data-suggest' => '0',
],
'#weight' => 17,
'#weight' => 20,
];

$form['field_tags_replace']['field_suggest_title'] = [
'#markup' => "<h4 class='label form-required mt-4'>Tags</h4>",
];

$form['field_tags_replace']['field_suggest'] = [
Expand Down Expand Up @@ -389,7 +548,7 @@ function access_misc_form_alter(&$form, FormStateInterface $form_state, $form_id
</div>
<div id='tag-suggestions'></div>
<details class='tags m-0 mb-8'><summary class='font-bold'>$tag_summary</summary>$output</details>",
'#weight' => 17,
'#weight' => 20,
'#allowed_tags' => [
'button',
'details',
Expand All @@ -405,6 +564,11 @@ function access_misc_form_alter(&$form, FormStateInterface $form_state, $form_id
$form['#attached']['library'][] = 'access_misc/node_add_tags';
$form['#attached']['library'][] = 'access_misc/events';

// Registration form.
$form['event_registration']['widget'][0]['unique_email_address']['#default_value'] = 1;
$form['event_registration']['widget'][0]['unique_email_address']['#access'] = FALSE;
$form['event_registration']['widget'][0]['permitted_roles']['#default_value'] = ['authenticated'];
$form['event_registration']['widget'][0]['permitted_roles']['#access'] = FALSE;
}
// Custom tags on /form/ci-link webform.
if ($form_id == 'webform_submission_resource_add_form' || $form_id == 'webform_submission_resource_edit_form') {
Expand Down Expand Up @@ -476,6 +640,60 @@ function access_misc_form_alter(&$form, FormStateInterface $form_state, $form_id
}
}

/**
* Custom submit handler for registrant form.
*/
function access_misc_registrant_submit($form, FormStateInterface $form_state) {
// Invalidate cache on Events Facet view.
$cache_tags = ['config:views.view.events_facet'];
\Drupal\Core\Cache\Cache::invalidateTags($cache_tags);
}

/**
* Custom submit handler for registrant form to email user.
*/
function access_misc_registrant_email_submit($form, FormStateInterface $form_state) {
// Get url.
$url = \Drupal::request()->getRequestUri();
$url = explode('/', $url);
$event_instance_id = $url[2];
// Entity load eventinctance by id.
$event_instance = \Drupal::entityTypeManager()->getStorage('eventinstance')->load($event_instance_id);
$series = $event_instance->getEventSeries();
$series_title = $series->get('title')->value;
$series_contact = $series->get('field_contact')->getValue()[0]['value'];
$contact = $series_contact ? t('In the meantime, if you have any questions or wish to withdraw from the waitlist, please contact us at ') . $series_contact . '.': '';
$start_date = $event_instance->get('date')->start_date->__toString();
$start_date = date('F j, Y', strtotime($start_date));
// Turn $series_title into a link to the event.
$series_title_url = "<a href='/events/$event_instance_id'>$series_title</a>";

$registered_person_email = Xss::filter($form_state->getValues()['email'][0]['value']);
$name = Xss::filter($form_state->getValues()['field_first_name'][0]['value']) . ' ' . Xss::filter($form_state->getValues()['field_last_name'][0]['value']);
$uid = Xss::filter($form_state->getValues()['user_id'][0]['target_id']);
$waitlist = Xss::filter($form_state->getValues()['add_to_waitlist']);

$policy = 'access_misc';

// Get list of unique emails.
$variables = [
'title' => $series_title,
'name' => $name,
'title_link' => $series_title_url,
'start_date' => $start_date,
'contact' => $contact,
];

if ($waitlist) {
$policy_subtype = 'waitlist';
\Drupal::service('access_misc.symfony.mail')->email($policy, $policy_subtype, $registered_person_email, $variables);
}
else {
$policy_subtype = 'register';
\Drupal::service('access_misc.symfony.mail')->email($policy, $policy_subtype, $registered_person_email, $variables);
}
}

/**
* Custom submit handler for user_form.
*/
Expand Down
18 changes: 18 additions & 0 deletions modules/access_misc/access_misc.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ wvuf_api_integration.unmask:
_title: 'Unmask'
requirements:
_user_is_masquerading: 'TRUE'
misc.eventApprove:
path: '/events/{event_id}/waitlist/approve'
defaults:
_controller: '\Drupal\access_misc\Controller\EventWaitlist::approve'
_title: 'Approved'
requirements:
_custom_access: '\Drupal\access_misc\Controller\EventWaitlist::isAuthor'
options:
no_cache: 'TRUE'
misc.eventDeny:
path: '/events/{event_id}/waitlist/unapprove'
defaults:
_controller: '\Drupal\access_misc\Controller\EventWaitlist::unapprove'
_title: 'Unapproved'
requirements:
_role: 'authenticated'
options:
no_cache: 'TRUE'
23 changes: 23 additions & 0 deletions modules/access_misc/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,26 @@ if (radioSelect) {
let title = document.querySelector('#edit-title-0-value--description');
title.textContent = title.textContent;
title.innerHTML = 'The title of your event. Please do not include date or location information in the title since that is listed elsewhere in the event.';

// Overwrite text in # to 'Event Title'.
let virtualTitle = document.querySelector('#edit-field-event-virtual-meeting-link-wrapper label');
console.log(virtualTitle.textContent);
virtualTitle.insertAdjacentHTML('afterend', '<div class="form-item__description description form-item__description--label-help">Provide link to virtual meeting. If there is one.</div>');

// If #edit-event-registration-0-registration is checked or unchecked add a console.log message.
let registration = document.querySelector('#edit-event-registration-0-registration');
registration.addEventListener('change', function() {
checkRegistration();
});

function checkRegistration() {
if (registration.checked) {
document.getElementById("edit-field-registration-0-uri").value = 'http://example.com';
document.getElementById("edit-field-registration-wrapper").style.display = 'none';
} else {
document.getElementById("edit-field-registration-0-uri").value = '';
document.getElementById("edit-field-registration-wrapper").style.display = 'block';
}
}

checkRegistration();
Loading