From 185bc93a91a45462f592109272ce74828f4a7a9f Mon Sep 17 00:00:00 2001
From: ryankavalsky <ryankavalsky@3075433.no-reply.drupal.org>
Date: Sat, 26 Dec 2020 09:52:04 -0700
Subject: [PATCH] Issue #3183502 by ryankavalsky, owenbush: Allow Registration
 Messages to be Customized

---
 ..._events_registration.registrant.config.yml |  6 ++
 .../recurring_events_registration.install     | 15 +++++
 .../src/Entity/RegistrantViewsData.php        | 23 --------
 .../src/Form/RegistrantForm.php               | 10 ++--
 .../src/Form/RegistrantSettingsForm.php       | 56 +++++++++++++++++++
 5 files changed, 82 insertions(+), 28 deletions(-)
 delete mode 100644 modules/recurring_events_registration/src/Entity/RegistrantViewsData.php

diff --git a/modules/recurring_events_registration/config/install/recurring_events_registration.registrant.config.yml b/modules/recurring_events_registration/config/install/recurring_events_registration.registrant.config.yml
index 54f3f303..586238d0 100644
--- a/modules/recurring_events_registration/config/install/recurring_events_registration.registrant.config.yml
+++ b/modules/recurring_events_registration/config/install/recurring_events_registration.registrant.config.yml
@@ -3,6 +3,12 @@ limit: 10
 date_format: 'F jS, Y h:iA'
 title: '[registrant:email]'
 email_notifications: true
+successfully_registered: Registrant successfully created.
+successfully_registered_waitlist: Successfully registered to the waitlist.
+successfully_updated: Registrant successfully updated.
+successfully_updated_waitlist: Successfully updated waitlist registrant.
+already_registered: User already registered for this event.
+registration_closed: Unfortunately, registration is not available at this time.
 registration_notification_enabled: true
 registration_notification_subject: 'You''ve Successfully Registered'
 registration_notification_body: "Your registration for the [eventinstance:title] [eventinstance:reg_type] was successful.\r\n\r\nModify your registration: [registrant:edit_url]\r\nDelete your registration: [registrant:delete_url]"
diff --git a/modules/recurring_events_registration/recurring_events_registration.install b/modules/recurring_events_registration/recurring_events_registration.install
index 9958d201..a49ff68f 100644
--- a/modules/recurring_events_registration/recurring_events_registration.install
+++ b/modules/recurring_events_registration/recurring_events_registration.install
@@ -175,3 +175,18 @@ function recurring_events_registration_update_8003() {
     }
   }
 }
+
+/**
+ * Add the default registration message configurations.
+ */
+function recurring_events_registration_update_8004() {
+  // Configure the registrantion messages.
+  \Drupal::configFactory()->getEditable('recurring_events_registration.registrant.config')
+    ->set('successfully_registered', 'Registrant successfully created.')
+    ->set('successfully_registered_waitlist', 'Successfully registered to the waitlist.')
+    ->set('successfully_updated', 'Registrant successfully updated.')
+    ->set('successfully_updated_waitlist', 'Successfully updated waitlist registrant.')
+    ->set('already_registered', 'ser already registered for this event.')
+    ->set('registration_closed', 'Unfortunately, registration is not available at this time.')
+    ->save(TRUE);
+}
\ No newline at end of file
diff --git a/modules/recurring_events_registration/src/Entity/RegistrantViewsData.php b/modules/recurring_events_registration/src/Entity/RegistrantViewsData.php
deleted file mode 100644
index fc4828c3..00000000
--- a/modules/recurring_events_registration/src/Entity/RegistrantViewsData.php
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-
-namespace Drupal\recurring_events_registration\Entity;
-
-use Drupal\views\EntityViewsData;
-
-/**
- * Provides Views data for Registrant entities.
- */
-class RegistrantViewsData extends EntityViewsData {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getViewsData() {
-    $data = parent::getViewsData();
-
-    // Additional information for Views integration, such as table joins, can be
-    // put here.
-    return $data;
-  }
-
-}
diff --git a/modules/recurring_events_registration/src/Form/RegistrantForm.php b/modules/recurring_events_registration/src/Form/RegistrantForm.php
index c7995401..2013a09e 100644
--- a/modules/recurring_events_registration/src/Form/RegistrantForm.php
+++ b/modules/recurring_events_registration/src/Form/RegistrantForm.php
@@ -421,16 +421,16 @@ class RegistrantForm extends ContentEntityForm {
 
       switch ($status) {
         case SAVED_NEW:
-          $message = $this->t('Registrant successfully created.');
+          $message = $this->t($this->config('recurring_events_registration.registrant.config')->get('successfully_registered'));
           if ($add_to_waitlist) {
-            $message = $this->t('Successfully registered to the waitlist.');
+            $message = $this->t($this->config('recurring_events_registration.registrant.config')->get('successfully_registered_waitlist'));
           }
           break;
 
         default:
-          $message = $this->t('Registrant successfully updated.');
+          $message = $this->t($this->config('recurring_events_registration.registrant.config')->get('successfully_registered_waitlist'));
           if ($add_to_waitlist) {
-            $message = $this->t('Successfully updated waitlist registrant.');
+            $message = $this->t($this->config('recurring_events_registration.registrant.config')->get('successfully_registered_waitlist'));
           }
           break;
       }
@@ -452,7 +452,7 @@ class RegistrantForm extends ContentEntityForm {
       $this->cacheTagsInvalidator->invalidateTags($tags);
     }
     else {
-      $this->messenger->addMessage($this->t('Unfortunately, registration is not available at this time.'));
+      $this->messenger->addMessage($this->t($this->config('recurring_events_registration.registrant.config')->get('registration_closed')));
     }
 
   }
diff --git a/modules/recurring_events_registration/src/Form/RegistrantSettingsForm.php b/modules/recurring_events_registration/src/Form/RegistrantSettingsForm.php
index 5add1a1a..7a51841a 100644
--- a/modules/recurring_events_registration/src/Form/RegistrantSettingsForm.php
+++ b/modules/recurring_events_registration/src/Form/RegistrantSettingsForm.php
@@ -97,6 +97,12 @@ class RegistrantSettingsForm extends ConfigFormBase {
       ->set('limit', $form_state->getValue('limit'))
       ->set('date_format', $form_state->getValue('date_format'))
       ->set('title', $form_state->getValue('title'))
+      ->set('successfully_registered', $form_state->getValue('successfully_registered'))
+      ->set('successfully_registered_waitlist', $form_state->getValue('successfully_registered_waitlist'))
+      ->set('successfully_updated', $form_state->getValue('successfully_updated'))
+      ->set('successfully_updated_waitlist', $form_state->getValue('successfully_updated_waitlist'))
+      ->set('already_registered', $form_state->getValue('already_registered'))
+      ->set('registration_closed', $form_state->getValue('registration_closed'))
       ->set('email_notifications', $form_state->getValue('email_notifications'));
 
     $notification_types = [];
@@ -180,6 +186,56 @@ class RegistrantSettingsForm extends ConfigFormBase {
 
     $form['display']['tokens'] = $registrant_tokens;
 
+    $form['messages'] = [
+      '#type' => 'details',
+      '#title' => $this->t('Registration Messages'),
+      '#open' => TRUE,
+    ];
+
+    $form['messages']['successfully_registered'] = [
+      '#type' => 'textarea',
+      '#title' => $this->t('Successful Registration'),
+      '#description' => $this->t('This message will show in the message area when a user successfully registers for an event.'),
+      '#default_value' => $config->get('successfully_registered'),
+    ];
+
+    $form['messages']['successfully_registered_waitlist'] = [
+      '#type' => 'textarea',
+      '#title' => $this->t('Successful Registration (Waitlist)'),
+      '#description' => $this->t('This message will show in the message area when a user successfully registers for an event\'s waitlist.'),
+      '#default_value' => $config->get('successfully_registered_waitlist'),
+    ];
+
+    $form['messages']['successfully_updated'] = [
+      '#type' => 'textarea',
+      '#title' => $this->t('Successful Update'),
+      '#description' => $this->t('This message will show in the message area when a user successfully updates a registration for an event.'),
+      '#default_value' => $config->get('successfully_updated'),
+    ];
+
+    $form['messages']['successfully_updated_waitlist'] = [
+      '#type' => 'textarea',
+      '#title' => $this->t('Successful Update (Waitlist)'),
+      '#description' => $this->t('This message will show in the message area when a user successfully updates a registration for an event\'s waitlist.'),
+      '#default_value' => $config->get('successfully_updated_waitlist'),
+    ];
+
+    $form['messages']['already_registered'] = [
+      '#type' => 'textarea',
+      '#title' => $this->t('Duplicate Registration'),
+      '#description' => $this->t('This message will show in the message area when a user tries to register a second time for the same event.'),
+      '#default_value' => $config->get('already_registered'),
+    ];
+
+    $form['messages']['registration_closed'] = [
+      '#type' => 'textarea',
+      '#title' => $this->t('Registration Window Closed'),
+      '#description' => $this->t('This message will show in the message area when a user tries to register for an event for which registrations are closed.'),
+      '#default_value' => $config->get('registration_closed'),
+    ];
+
+    $form['messages']['tokens'] = $registrant_tokens;
+
     $form['notifications'] = [
       '#type' => 'details',
       '#title' => $this->t('Email Notifications'),
-- 
GitLab