Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
featuriz authored Dec 2, 2021
1 parent 1e384e9 commit 08f3271
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rsvplist.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: RSVP List
description: Allows users to RSVP for Events and provides a contact list for Administrators.
package: FZ
configure: rsvplist.admin_settings

type: module
core_version_requirement: ^8.8.0 || ^9.0
version: 1.0
59 changes: 59 additions & 0 deletions rsvplist.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
function rsvplist_schema() {
$schema['rsvplist'] = [
'description' => 'Stores email, timestamp, nid and uid for an rsvp',
'fields' => [
'id' => [
'description' => 'The primary identifer for the record.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'uid' => [
'description' => 'The {users}.uid that added this rsvp.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'nid' => [
'description' => 'The {node}.nid for this rsvp.',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
'default' => 0,
],
'mail' => [
'description' => 'User\'s email address.',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
'default' => '',
],
'created' => [
'description' => 'Timestamp for when rsvp was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => ['id'],
'indexes' => [
'node' => ['nid'],
'node_user' => ['nid', 'uid'],
],
];

$schema['rsvplist_enabled'] = [
'description' => 'Tracks wheter rsvplist is enabled for a node.',
'fields' => [
'nid' => [
'description' => 'The {node}.id that has rsvplist enabled.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => ['nid'],
];
return $schema;
}
13 changes: 13 additions & 0 deletions rsvplist.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
rsvplist.admin_settings:
title: 'RSVP List Settings'
description: 'Control the display of RSVP Form'
route_name: rsvplist.admin_settings
parent: system.admin_config_content
weight: 10

rsvplist.report:
title: 'List of RSVP Submissions'
description: 'View Listing of RSVPs'
route_name: rsvplist.report
parent: system.admin_reports
weight: 0
56 changes: 56 additions & 0 deletions rsvplist.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_form_alter()
* Alter the form Add/Edit form to include admin setting for displaying
* RSVPBlock with content
*/

function rsvplist_form_node_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $formState, $form_id) {
$node = $formState->getFormObject()->getEntity();
$current_node_type = $node->getType();
$config = \Drupal::config('rsvplist.settings');
$types = $config->get('allowed_types', []);
// RSVP options for administrators
if (in_array($current_node_type, $types)) {
$form['rsvplist'] = [
'#type' => 'details',
'#title' => t('RSVP Collections'),
'#access' => \Drupal::currentUser()->hasPermission('administer rsvplist'),
'#group' => 'advanced',
'#weight' => 100,
];
/** @var \Drupal\rsvplist\EnablerService $enabler */
$enabler = Drupal::service('rsvplist.enabler');
$form['rsvplist']['rsvplist_enabled'] = [
'#type' => 'checkbox',
'#title' => t('Collect RSVP e-mail addresses for this node.'),
'#default_value' => $enabler->isEnabled($node),
];
foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'rsvplist_form_node_form_submit';
}
}
}
}

/**
* Form submission handler for RSVP item field on the node form.
*
* @see \rsvplist_form_node_form_alter()
*/
function rsvplist_form_node_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $formState) {
/** @var \Drupal\rsvplist\EnablerService $enabler */
$enabler = Drupal::service('rsvplist.enabler');
$node = $formState->getFormObject()->getEntity();
if ($enabled = $formState->getValue('rsvplist_enabled')) {
$enabler->setEnabled($node);
}
else {
$enabler->delEnabled($node);
}

}
10 changes: 10 additions & 0 deletions rsvplist.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
view rsvplist:
title: 'View RSVP Form'
description: 'View and Submit the RSVP Form'
access rsvplist report:
title: 'Acess List of RSVPs'
description: 'View the report listing all RSVPs Submitted.'
administer rsvplist:
title: 'Administer RSVP Settings'
description: 'Access the RSVP Administrative settings page.'
restrict access: true
23 changes: 23 additions & 0 deletions rsvplist.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# We moved this to a block
#rsvplist.form:
# path: '/rsvplist'
# defaults:
# _form: '\Drupal\rsvplist\Form\RSVPForm'
# _title: 'RSVP to this Event'
# requirements:
# _permission: 'view rsvplist'
rsvplist.admin_settings:
path: '/admin/config/content/rsvplist'
defaults:
_form: '\Drupal\rsvplist\Form\RSVPSettingsForm'
_title: 'RSVP List Settings'
requirements:
_permission: 'administer rsvplist'

rsvplist.report:
path: '/admin/reports/rsvplist'
defaults:
_controller: '\Drupal\rsvplist\Controller\ReportController::report'
_title: 'List of RSVPs'
requirements:
_permission: 'view rsvplist'
4 changes: 4 additions & 0 deletions rsvplist.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
rsvplist.enabler:
class: \Drupal\rsvplist\EnablerService
arguments: []

0 comments on commit 08f3271

Please sign in to comment.