{% if not currentUser %} {% do craft.app.session.setFlash('info', 'event.subscribe.notAuthenticated'|t({registerUrl: url('registration')})) %} {% endif %} {% requireLogin %} {% if not id %} {% redirect "/" %} {% endif %} {% set event = craft.entries.id(id).section('events').one() %} {% if not event %} {% redirect "/" %} {% endif %} {% if not event.registrationEnabled %} {% redirect event.url %} {% endif %} {% macro errorList(errors) %} {% if errors %} {{ ul(errors, {class: 'errors'}) }} {% endif %} {% endmacro %} {# Load section + entry type definitions: #} {% set section = craft.app.entries.getSectionByHandle('eventSubscriptions') %} {% set entryType = craft.app.entries.getEntryTypeByHandle('eventSubscription') %} {# If there were any validation errors, an `entry` variable will be passed back to the template, containing the POSTed values, as-is, and validation errors. If that’s *not* present, we stub out a new entry object: #} {% set entry = entry ?? create({ class: 'craft\\elements\\Entry', sectionId: section.id, typeId: entryType.id, }) %} {% extends "_layout" %} {% block content %}

{{ 'form.event.subscribe.title'|t }}

{% include 'events/_event-info.twig' with {'includeFootnotes': true} %}
{{ 'form.event.subscribe.name'|t }}: {{ currentUser.fullName }}
{# Check if already subscribed #} {% set subscribed = craft.entries .section('eventSubscriptions') .relatedTo([ 'and', { targetElement: event, field: 'event', }, { targetElement: currentUser, field: 'user', }, ]) .status(null) .one() %} {% if subscribed %}

{{ ('form.event.subscribe.message.' ~ subscribed.approvalStatus)|t }}

{% else %}
{{ csrfInput() }} {{ actionInput('entries/save-entry') }} {{ redirectInput('event-subscription/' ~ event.id ~ '/confirm') }} {{ hiddenInput('sectionId', entry.sectionId) }} {{ hiddenInput('typeId', entry.typeId) }} {{ hiddenInput('enabled', false) }} {{ hiddenInput('fields[event][]', event.id) }} {{ hiddenInput('fields[user][]', currentUser.id) }} {% if event.subscribersInformation %}
{{ event.subscribersInformation }}
{% endif %}
{{ _self.errorList(entry.getErrors('additionalInformation')) }}
{% endif %}
{% if event.dateLabel %}
(1) {{ 'form.event.subscribe.noteDate'|t }}
{% endif %}
{% endblock %}