class EventAnEnrollForm in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 8.3 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 8.4 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 8.5 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 8.7 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 8.8 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 10.3.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 10.0.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 10.1.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- 10.2.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
Class EventAnEnrollForm.
@package Drupal\social_event_an_enroll\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\social_event\Form\EnrollActionForm implements ContainerInjectionInterface
- class \Drupal\social_event_an_enroll\Form\EventAnEnrollForm
- class \Drupal\social_event\Form\EnrollActionForm implements ContainerInjectionInterface
Expanded class hierarchy of EventAnEnrollForm
1 string reference to 'EventAnEnrollForm'
- social_event_an_enroll.routing.yml in modules/
social_features/ social_event/ modules/ social_event_an_enroll/ social_event_an_enroll.routing.yml - modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.routing.yml
File
- modules/
social_features/ social_event/ modules/ social_event_an_enroll/ src/ Form/ EventAnEnrollForm.php, line 19
Namespace
Drupal\social_event_an_enroll\FormView source
class EventAnEnrollForm extends EnrollActionForm {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'event_an_enroll_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$nid = $this->routeMatch
->getRawParameter('node');
// Load node object.
if (!is_null($nid) && !is_object($nid)) {
$node = Node::load($nid);
}
// Set hidden values.
$form['field_event'] = [
'#type' => 'hidden',
'#value' => $nid,
];
$form['field_first_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('First name'),
];
$form['field_last_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Last name'),
];
$form['field_email'] = [
'#type' => 'email',
'#required' => TRUE,
'#title' => $this
->t('Email address'),
'#description' => $this
->t('Enter your email, so we can send you event updates.'),
];
if ($this->moduleHandler
->moduleExists('data_policy')) {
$data_policy_config = $this->configFactory
->get('data_policy.data_policy');
// Check if data policy is created.
if (!empty($data_policy_config
->get('entity_id'))) {
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$link = Link::createFromRoute($this
->t('data policy'), 'data_policy.data_policy', [], [
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'title' => t('Data policy'),
'width' => 700,
'height' => 700,
]),
],
]);
$enforce_consent = !empty($data_policy_config
->get('enforce_consent'));
$form['data_policy'] = [
'#type' => 'checkbox',
'#title' => $this
->t('I agree with the @url', [
'@url' => $link
->toString(),
]),
'#required' => $enforce_consent,
];
}
}
$submit_text = $this
->t('Enroll in event');
$enrollment_open = TRUE;
// Add the enrollment closed label.
if ($this
->eventHasBeenFinished($node)) {
$submit_text = $this
->t('Event has passed');
$enrollment_open = FALSE;
}
$form['actions']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#button_level' => 'raised',
'#value' => $submit_text,
'#disabled' => !$enrollment_open,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$current_user = $this->currentUser;
$uid = $current_user
->id();
if ($current_user
->isAnonymous()) {
$nid = $form_state
->getValue('field_event');
$values = $form_state
->getValues();
$values['user_id'] = $uid;
$values['field_account'] = $uid;
$values['field_enrollment_status'] = '1';
// Check if there is enrollment with the same email.
$conditions = [
'field_email' => $values['field_email'],
'field_event' => $nid,
];
$enrollments = $this->entityStorage
->loadByProperties($conditions);
if ($enrollment = array_pop($enrollments)) {
$values['field_token'] = $enrollment
->get('field_token')
->getString();
drupal_set_message($this
->t('You have been already enrolled to this event. You have also received a notification via email.'));
}
else {
$values['field_token'] = Crypt::randomBytesBase64();
// Create a new enrollment for the event.
$enrollment = EventEnrollment::create($values);
$enrollment
->save();
// Invalidate cache for our enrollment cache tag in
// social_event_node_view_alter().
$cache_tags[] = 'enrollment:' . $nid . '-' . $uid;
$cache_tags[] = 'node:' . $nid;
Cache::invalidateTags($cache_tags);
drupal_set_message($this
->t('You have successfully enrolled to this event. You have also received a notification via email.'));
}
// Redirect anonymous use to login page before enrolling to an event.
$form_state
->setRedirect('entity.node.canonical', [
'node' => $nid,
], [
'query' => [
'token' => $values['field_token'],
],
]);
// Send email if the setting is enabled.
$event_an_enroll_config = $this
->config('social_event_an_enroll.settings');
if ($event_an_enroll_config
->get('event_an_enroll_email_notify')) {
social_event_an_enroll_send_mail($values);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EnrollActionForm:: |
protected | property |
The config factory. Overrides FormBase:: |
|
EnrollActionForm:: |
protected | property | The current user. | |
EnrollActionForm:: |
protected | property | The node storage for event enrollments. | |
EnrollActionForm:: |
protected | property | The entity type manager. | |
EnrollActionForm:: |
protected | property | The module handler. | |
EnrollActionForm:: |
protected | property |
The routing matcher to get the nid. Overrides FormBase:: |
|
EnrollActionForm:: |
protected | property | The user storage. | |
EnrollActionForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
EnrollActionForm:: |
protected | function | Function to determine if an event has been finished. | |
EnrollActionForm:: |
public | function | Get group object where event enrollment is posted in. | |
EnrollActionForm:: |
public | function | Constructs an Enroll Action Form. | |
EventAnEnrollForm:: |
public | function |
Form constructor. Overrides EnrollActionForm:: |
|
EventAnEnrollForm:: |
public | function |
Returns a unique string identifying the form. Overrides EnrollActionForm:: |
|
EventAnEnrollForm:: |
public | function |
Form submission handler. Overrides EnrollActionForm:: |
|
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |