diff --git a/src/View/QuizViewBuilder.php b/src/View/QuizViewBuilder.php index 94a9c729254b98720268c2ef56beea8ff4e20b58..d78334291015b8858f8442ee03a3bf6f733b1c2d 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; @@ -38,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, @@ -46,6 +49,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 +65,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 +137,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 +182,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,17 +201,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', - ], + $build['link'] = $quiz->toLink($this->t('Start @quiz', ['@quiz' => QuizUtil::getQuizName()]), 'take', [ + '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()) {