From 69e67e2259eec908cf75d1c07ca77b9894b301dd Mon Sep 17 00:00:00 2001 From: Andrey Baklanov Date: Tue, 4 Feb 2025 14:25:24 +0200 Subject: [PATCH 1/6] ASU-1729 hide endtime text if date in past --- .../templates/content/node--project--full.html.twig | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 %}
From f453147b4ab38375b4dc60051e870f27fed23130 Mon Sep 17 00:00:00 2001 From: Andrey Baklanov Date: Thu, 6 Feb 2025 11:08:10 +0200 Subject: [PATCH 2/6] Event_Dispatcher null logger and fix --- .../custom/asu_application/src/Form/ApplicationForm.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/modules/custom/asu_application/src/Form/ApplicationForm.php b/public/modules/custom/asu_application/src/Form/ApplicationForm.php index c4710ee1a..117b7404b 100644 --- a/public/modules/custom/asu_application/src/Form/ApplicationForm.php +++ b/public/modules/custom/asu_application/src/Form/ApplicationForm.php @@ -91,6 +91,13 @@ public static function create(ContainerInterface $container) { $instance->routeMatch = $container->get('current_route_match'); $instance->eventDispatcher = $container->get('event_dispatcher'); + if (!$instance->eventDispatcher) { + \Drupal::logger('asu_application')->error('ApplicationForm::create() - eventDispatcher is NULL for user_id={user}', [ + 'user' => \Drupal::currentUser()->id(), + ]); + $instance->eventDispatcher = \Drupal::service('event_dispatcher'); + } + return $instance; } From 1511d7f0d6c468caa965384dda51defc5768ed56 Mon Sep 17 00:00:00 2001 From: Andrey Baklanov Date: Thu, 6 Feb 2025 16:04:34 +0200 Subject: [PATCH 3/6] Event_Dispatcher null more logger --- .../custom/asu_application/src/Form/ApplicationForm.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/modules/custom/asu_application/src/Form/ApplicationForm.php b/public/modules/custom/asu_application/src/Form/ApplicationForm.php index 117b7404b..9c9f5a617 100644 --- a/public/modules/custom/asu_application/src/Form/ApplicationForm.php +++ b/public/modules/custom/asu_application/src/Form/ApplicationForm.php @@ -92,11 +92,11 @@ public static function create(ContainerInterface $container) { $instance->eventDispatcher = $container->get('event_dispatcher'); if (!$instance->eventDispatcher) { - \Drupal::logger('asu_application')->error('ApplicationForm::create() - eventDispatcher is NULL for user_id={user}', [ - 'user' => \Drupal::currentUser()->id(), - ]); + $this->logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is NULL :'); + $this->logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); + $this->logger('asu_application')->critical('Set eventDispatcher ' . \Drupal::service('event_dispatcher')); $instance->eventDispatcher = \Drupal::service('event_dispatcher'); - } + } return $instance; } From c4e00875156ad9045f1dbcfd5779bfa5aac8707a Mon Sep 17 00:00:00 2001 From: Andrey Baklanov Date: Fri, 7 Feb 2025 11:22:53 +0200 Subject: [PATCH 4/6] Event_Dispatcher null more logger --- .../asu_application/src/Form/ApplicationForm.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/public/modules/custom/asu_application/src/Form/ApplicationForm.php b/public/modules/custom/asu_application/src/Form/ApplicationForm.php index 9c9f5a617..0032993b5 100644 --- a/public/modules/custom/asu_application/src/Form/ApplicationForm.php +++ b/public/modules/custom/asu_application/src/Form/ApplicationForm.php @@ -91,7 +91,18 @@ public static function create(ContainerInterface $container) { $instance->routeMatch = $container->get('current_route_match'); $instance->eventDispatcher = $container->get('event_dispatcher'); - if (!$instance->eventDispatcher) { + if ($instance->eventDispatcher) { + \Drupal::logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is :'); + \Drupal::logger('asu_application')->critical($instance->eventDispatcher); + \Drupal::logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); + $this->logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is :'); + $this->logger('asu_application')->critical($instance->eventDispatcher); + $this->logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); + } else { + \Drupal::logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is NULL :'); + \Drupal::logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); + \Drupal::logger('asu_application')->critical('Set eventDispatcher ' . \Drupal::service('event_dispatcher')); + $instance->eventDispatcher = \Drupal::service('event_dispatcher'); $this->logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is NULL :'); $this->logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); $this->logger('asu_application')->critical('Set eventDispatcher ' . \Drupal::service('event_dispatcher')); From 977e12cc512873bb7da37990cbc60d19a73d296c Mon Sep 17 00:00:00 2001 From: Andrey Baklanov Date: Fri, 7 Feb 2025 12:09:12 +0200 Subject: [PATCH 5/6] Event_Dispatcher null more logger remove this --- .../src/Form/ApplicationForm.php | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/public/modules/custom/asu_application/src/Form/ApplicationForm.php b/public/modules/custom/asu_application/src/Form/ApplicationForm.php index 0032993b5..0efc34c97 100644 --- a/public/modules/custom/asu_application/src/Form/ApplicationForm.php +++ b/public/modules/custom/asu_application/src/Form/ApplicationForm.php @@ -92,22 +92,15 @@ public static function create(ContainerInterface $container) { $instance->eventDispatcher = $container->get('event_dispatcher'); if ($instance->eventDispatcher) { - \Drupal::logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is :'); - \Drupal::logger('asu_application')->critical($instance->eventDispatcher); - \Drupal::logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); - $this->logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is :'); - $this->logger('asu_application')->critical($instance->eventDispatcher); - $this->logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); - } else { - \Drupal::logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is NULL :'); - \Drupal::logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); - \Drupal::logger('asu_application')->critical('Set eventDispatcher ' . \Drupal::service('event_dispatcher')); + \Drupal::logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is: ' . get_class($instance->eventDispatcher)); + \Drupal::logger('asu_application')->critical('user_id=' . \Drupal::currentUser()->id()); + } else { + \Drupal::logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is NULL'); + \Drupal::logger('asu_application')->critical('user_id=' . \Drupal::currentUser()->id()); + \Drupal::logger('asu_application')->critical('Set eventDispatcher to: ' . get_class(\Drupal::service('event_dispatcher'))); $instance->eventDispatcher = \Drupal::service('event_dispatcher'); - $this->logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is NULL :'); - $this->logger('asu_application')->critical('user_id={user} ' . currentUser()->id()); - $this->logger('asu_application')->critical('Set eventDispatcher ' . \Drupal::service('event_dispatcher')); - $instance->eventDispatcher = \Drupal::service('event_dispatcher'); - } + } + return $instance; } From 3fd7796cf137529dfb4b09276ee894bb2c5ddec2 Mon Sep 17 00:00:00 2001 From: Andrey Baklanov Date: Tue, 11 Feb 2025 13:14:41 +0200 Subject: [PATCH 6/6] restore eventDispatcher and application in form after ajax request --- .../src/Form/ApplicationForm.php | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/public/modules/custom/asu_application/src/Form/ApplicationForm.php b/public/modules/custom/asu_application/src/Form/ApplicationForm.php index 0efc34c97..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} */ @@ -91,17 +103,6 @@ public static function create(ContainerInterface $container) { $instance->routeMatch = $container->get('current_route_match'); $instance->eventDispatcher = $container->get('event_dispatcher'); - if ($instance->eventDispatcher) { - \Drupal::logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is: ' . get_class($instance->eventDispatcher)); - \Drupal::logger('asu_application')->critical('user_id=' . \Drupal::currentUser()->id()); - } else { - \Drupal::logger('asu_application')->critical('ApplicationForm::create() - eventDispatcher is NULL'); - \Drupal::logger('asu_application')->critical('user_id=' . \Drupal::currentUser()->id()); - \Drupal::logger('asu_application')->critical('Set eventDispatcher to: ' . get_class(\Drupal::service('event_dispatcher'))); - $instance->eventDispatcher = \Drupal::service('event_dispatcher'); - } - - return $instance; } @@ -109,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; @@ -217,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(); @@ -495,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); } @@ -583,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, ]); - + } /**