diff --git a/public/modules/custom/asu_application/src/Form/ApplicationForm.php b/public/modules/custom/asu_application/src/Form/ApplicationForm.php index c4710ee1a..107f892d7 100644 --- a/public/modules/custom/asu_application/src/Form/ApplicationForm.php +++ b/public/modules/custom/asu_application/src/Form/ApplicationForm.php @@ -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} */ @@ -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; @@ -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(); @@ -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); } @@ -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, ]); - + } /** diff --git a/public/themes/custom/asuntotuotanto/templates/content/node--project--full.html.twig b/public/themes/custom/asuntotuotanto/templates/content/node--project--full.html.twig index 189d04ee1..3015715ff 100644 --- a/public/themes/custom/asuntotuotanto/templates/content/node--project--full.html.twig +++ b/public/themes/custom/asuntotuotanto/templates/content/node--project--full.html.twig @@ -228,13 +228,15 @@ {% endtrans %} {% endif %}

-

- {% 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 %} +

{% trans %} The application period for this project starts on {{ application_start_time }} and ends on {{ application_end_time }}. {% endtrans %} - {% endif %} -

+

+ {% endif %}