From 0651444f9da051ccdf366226778ec2ad80e0d793 Mon Sep 17 00:00:00 2001 From: Stephen Mustgrave <smustgrave@gmail.com> Date: Wed, 19 Mar 2025 14:39:15 -0400 Subject: [PATCH 1/3] Issue #1999720 by dmitri.daranuta, djdevin: Quiz Availability time not respecting site default time zone --- src/View/QuizViewBuilder.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/View/QuizViewBuilder.php b/src/View/QuizViewBuilder.php index 94a9c729..67312ca9 100644 --- a/src/View/QuizViewBuilder.php +++ b/src/View/QuizViewBuilder.php @@ -4,6 +4,7 @@ namespace Drupal\quiz\View; use Drupal\Core\Access\AccessResultReasonInterface; use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -46,6 +47,7 @@ class QuizViewBuilder extends EntityViewBuilder { Registry $theme_registry, EntityDisplayRepositoryInterface $entity_display_repository, protected RouteMatchInterface $routeMatch, + protected DateFormatterInterface $dateFormatter, ) { parent::__construct($entity_type, $entity_repository, $language_manager, $theme_registry, $entity_display_repository); } @@ -61,6 +63,7 @@ class QuizViewBuilder extends EntityViewBuilder { $container->get('theme.registry'), $container->get('entity_display.repository'), $container->get('current_route_match'), + $container->get('date.formatter') ); $view_builder->setMessenger($container->get('messenger')); return $view_builder; @@ -132,13 +135,14 @@ class QuizViewBuilder extends EntityViewBuilder { ]; } else { + $quiz_date = $quiz->get('quiz_date'); $stats[] = [ ['header' => TRUE, 'data' => $this->t('Opens')], - $quiz->get('quiz_date')->value, + $this->dateFormatter->format($quiz_date->start_date->getTimestamp()), ]; $stats[] = [ ['header' => TRUE, 'data' => $this->t('Closes')], - $quiz->get('quiz_date')->end_value, + $this->dateFormatter->format($quiz_date->start_date->getTimestamp()), ]; } @@ -176,6 +180,8 @@ class QuizViewBuilder extends EntityViewBuilder { * * @return array * Array formed to hold "Take" component. + * + * @throws \Drupal\Core\Entity\EntityMalformedException */ protected function buildTakeComponent(Quiz $quiz): array { $build = []; @@ -193,8 +199,7 @@ class QuizViewBuilder extends EntityViewBuilder { } } - $build['link'] = $quiz - ->toLink($this->t('Start @quiz', ['@quiz' => QuizUtil::getQuizName()]), 'take', [ + $build['link'] = $quiz->toLink($this->t('Start @quiz', ['@quiz' => QuizUtil::getQuizName()]), 'take', [ 'language' => $this->languageManager->getCurrentLanguage(), 'attributes' => [ 'class' => [ -- GitLab From 25a0034022aca71e7d283224228369a906e79bb9 Mon Sep 17 00:00:00 2001 From: Stephen Mustgrave <smustgrave@gmail.com> Date: Wed, 19 Mar 2025 14:49:18 -0400 Subject: [PATCH 2/3] PHPCS --- src/View/QuizViewBuilder.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/View/QuizViewBuilder.php b/src/View/QuizViewBuilder.php index 67312ca9..67e179f1 100644 --- a/src/View/QuizViewBuilder.php +++ b/src/View/QuizViewBuilder.php @@ -39,6 +39,8 @@ class QuizViewBuilder extends EntityViewBuilder { * The entity display repository. * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch * The currently active route match object. + * @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter + * The date formatter service. */ public function __construct( EntityTypeInterface $entity_type, @@ -200,15 +202,15 @@ class QuizViewBuilder extends EntityViewBuilder { } $build['link'] = $quiz->toLink($this->t('Start @quiz', ['@quiz' => QuizUtil::getQuizName()]), 'take', [ - 'language' => $this->languageManager->getCurrentLanguage(), - 'attributes' => [ - 'class' => [ - 'quiz-start-link', - 'button', - ], + 'language' => $this->languageManager->getCurrentLanguage(), + 'attributes' => [ + 'class' => [ + 'quiz-start-link', + 'button', ], - ]) - ->toRenderable(); + ], + ]) + ->toRenderable(); } // Only display a message when there is a reason available. elseif ($access instanceof AccessResultReasonInterface && $access->getReason()) { -- GitLab From 85d42806af0ed48ba0d7e298d4ced74b41dfb6fb Mon Sep 17 00:00:00 2001 From: Stephen Mustgrave <smustgrave@gmail.com> Date: Wed, 19 Mar 2025 14:52:58 -0400 Subject: [PATCH 3/3] PHPCS --- src/View/QuizViewBuilder.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/View/QuizViewBuilder.php b/src/View/QuizViewBuilder.php index 67e179f1..d7833429 100644 --- a/src/View/QuizViewBuilder.php +++ b/src/View/QuizViewBuilder.php @@ -209,8 +209,7 @@ class QuizViewBuilder extends EntityViewBuilder { 'button', ], ], - ]) - ->toRenderable(); + ])->toRenderable(); } // Only display a message when there is a reason available. elseif ($access instanceof AccessResultReasonInterface && $access->getReason()) { -- GitLab