Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 29 additions & 2 deletions public/modules/custom/asu_application/src/Form/ApplicationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ class ApplicationForm extends ContentEntityForm {
*/
private ?EventDispatcherInterface $eventDispatcher = NULL;

protected $application;

protected function reloadApplication() {
$application_id = \Drupal::routeMatch()->getParameter('application')
?: \Drupal::request()->get('application_id');
if ($application_id) {
return \Drupal::entityTypeManager()->getStorage('asu_application')->load($application_id);
}

return null;
}

/**
* {@inheritdoc}
*/
Expand All @@ -98,7 +110,11 @@ public static function create(ContainerInterface $container) {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form_state->setRebuild(TRUE);
if (is_null($this->application)) {
$this->application = $this->reloadApplication();
}

$form_state->setRebuild(true);

$projectReference = $this->entity->project->first();
$project = $projectReference->entity;
Expand Down Expand Up @@ -206,6 +222,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'/contact/apply_for_free_apartment?project=' . $project_id;
return new RedirectResponse($freeApplicationUrl);
}

if (is_null($this->eventDispatcher)) {
$this->eventDispatcher = \Drupal::service('event_dispatcher');
}

$this->entity->save();

$url = $this->entity->toUrl()->toString();
Expand Down Expand Up @@ -484,6 +505,12 @@ private function handleApplicationEvent(array $form, FormStateInterface $form_st
$this->entity
);
}

if (is_null($this->eventDispatcher)) {
$this->eventDispatcher = \Drupal::service('event_dispatcher');
}


$this->eventDispatcher->dispatch($event, $eventName);
}

Expand Down Expand Up @@ -572,7 +599,7 @@ private function getApartments(Project $project, array $limit = []): ?array {
'application_start_date' => $project->field_application_start_time->value,
'application_end_date' => $project->field_application_end_time->value,
]);

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@
{% endtrans %}
{% endif %}
</p>
<p class="project__application-information">
{% if application_start_time != null and application_end_time != null %}
{% set end_time_unix = application_end_time|date("U") %}
{% set now_unix = "now"|date("U") %}
{% if application_start_time != null and application_end_time != null and end_time_unix > now_unix %}
<p class="project__application-information">
{% trans %}
The application period for this project starts on {{ application_start_time }} and ends on {{ application_end_time }}.
{% endtrans %}
{% endif %}
</p>
</p>
{% endif %}
</aside>
<div class="project__content">
<div class="project__type-and-address">
Expand Down
Loading