From bf15739c822ce90c27ce09a11e61b940d24e0b06 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Fri, 15 Dec 2023 09:54:21 -0800 Subject: [PATCH] Fix urls in templates --- modules/jumpstart_ui/jumpstart_ui.module | 2 +- .../src/Plugin/TwigPlugin/JumpstartUITwig.php | 2 +- .../Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php | 2 +- modules/stanford_events/stanford_events.module | 4 ++-- .../modules/stanford_person_importer/src/Cap.php | 2 +- .../src/Config/ConfigOverrides.php | 8 ++++---- modules/stanford_publication/src/CitationViewBuilder.php | 4 ++-- src/EventSubscriber/PreprocessEventSubscriber.php | 2 +- src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php | 2 +- stanford_profile_helper.module | 7 ++++--- 10 files changed, 18 insertions(+), 17 deletions(-) diff --git a/modules/jumpstart_ui/jumpstart_ui.module b/modules/jumpstart_ui/jumpstart_ui.module index fbe2c8b2..abb1429a 100755 --- a/modules/jumpstart_ui/jumpstart_ui.module +++ b/modules/jumpstart_ui/jumpstart_ui.module @@ -127,7 +127,7 @@ function jumpstart_ui_preprocess_pattern_localfooter(&$variables) { else { $route = Url::fromRoute('user.login'); } - $variables['weblogin_url'] = $route->toString(); + $variables['weblogin_url'] = $route->toString(TRUE)->getGeneratedUrl(); } } diff --git a/modules/jumpstart_ui/src/Plugin/TwigPlugin/JumpstartUITwig.php b/modules/jumpstart_ui/src/Plugin/TwigPlugin/JumpstartUITwig.php index b7fff502..ed4ffe18 100644 --- a/modules/jumpstart_ui/src/Plugin/TwigPlugin/JumpstartUITwig.php +++ b/modules/jumpstart_ui/src/Plugin/TwigPlugin/JumpstartUITwig.php @@ -83,7 +83,7 @@ public function renderClean($elements, $tags = '') { } // Renderer service only accepts arrays. - $rendered = is_array($elements) ? $this->renderer->render($elements) : $elements; + $rendered = is_array($elements) ? $this->renderer->renderPlain($elements) : $elements; if (!str_contains($tags, '')) { $tags .= ''; diff --git a/modules/stanford_courses/src/Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php b/modules/stanford_courses/src/Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php index 2aee0118..8b7850d5 100644 --- a/modules/stanford_courses/src/Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php +++ b/modules/stanford_courses/src/Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php @@ -172,7 +172,7 @@ public function massageFormValues(array $values, array $form, FormStateInterface $url['query']['view'] = $xml_querystring; $massaged_url = Url::fromUri($url['path'], ['query' => $url['query']]); - $values[$delta]['uri'] = $massaged_url->toString(); + $values[$delta]['uri'] = $massaged_url->toString(TRUE)->getGeneratedUrl(); } } return parent::massageFormValues($values, $form, $form_state); diff --git a/modules/stanford_events/stanford_events.module b/modules/stanford_events/stanford_events.module index 014b2948..866149ba 100755 --- a/modules/stanford_events/stanford_events.module +++ b/modules/stanford_events/stanford_events.module @@ -223,8 +223,8 @@ function stanford_events_preprocess_pattern_events_list(&$variables) { $values = $variables; // Make sure we have a string, not a Markup or array. - $start = (string) (is_array($values['start_month']) ? $renderer->render($values['start_month']) : $values['start_month']); - $end = (string) is_array($values['end_month']) ? $renderer->render($values['end_month']) : $values['end_month']; + $start = (string) (is_array($values['start_month']) ? $renderer->renderPlain($values['start_month']) : $values['start_month']); + $end = (string) is_array($values['end_month']) ? $renderer->renderPlain($values['end_month']) : $values['end_month']; $start_month = strtolower(trim(strip_tags($start))) ?: NULL; $end_month = strtolower(trim(strip_tags($end))) ?: NULL; diff --git a/modules/stanford_person/modules/stanford_person_importer/src/Cap.php b/modules/stanford_person/modules/stanford_person_importer/src/Cap.php index 68308e5b..e9e42e50 100644 --- a/modules/stanford_person/modules/stanford_person_importer/src/Cap.php +++ b/modules/stanford_person/modules/stanford_person_importer/src/Cap.php @@ -146,7 +146,7 @@ public function setClientSecret(string $secret): self { */ protected function getApiResponse(Url $url, array $options = []) { try { - $response = $this->client->request('GET', $url->toString(), $options); + $response = $this->client->request('GET', $url->toString(TRUE)->getGeneratedUrl(), $options); } catch (GuzzleException | \Exception $e) { $this->cache->delete('cap:access_token'); diff --git a/modules/stanford_person/modules/stanford_person_importer/src/Config/ConfigOverrides.php b/modules/stanford_person/modules/stanford_person_importer/src/Config/ConfigOverrides.php index a38ddfd4..525b101d 100644 --- a/modules/stanford_person/modules/stanford_person_importer/src/Config/ConfigOverrides.php +++ b/modules/stanford_person/modules/stanford_person_importer/src/Config/ConfigOverrides.php @@ -138,7 +138,7 @@ protected function getImporterUrls(): ?array { foreach ($urls as &$url) { $url = Url::fromUri($url); $url->mergeOptions(['query' => ['whitelist' => implode(',', $allowed_fields)]]); - $url = $url->toString(); + $url = $url->toString(TRUE)->getGeneratedUrl(); } return $urls; } @@ -219,7 +219,7 @@ protected function getSunetUrls(): array { $urls = []; foreach (array_chunk($sunets, self::URL_CHUNKS) as $chunk) { - $urls[] = $this->cap->getSunetUrl($chunk)->toString(); + $urls[] = $this->cap->getSunetUrl($chunk)->toString(TRUE)->getGeneratedUrl(); } return $urls; } @@ -238,13 +238,13 @@ protected function getUrlChunks(Url $url): array { $number_chunks = ceil($count / self::URL_CHUNKS); if ($number_chunks <= 1) { $url->mergeOptions(['query' => ['ps' => self::URL_CHUNKS]]); - return [$url->toString()]; + return [$url->toString(TRUE)->getGeneratedUrl()]; } $urls = []; for ($i = 1; $i <= $number_chunks; $i++) { $url->mergeOptions(['query' => ['p' => $i, 'ps' => self::URL_CHUNKS]]); - $urls[] = $url->toString(); + $urls[] = $url->toString(TRUE)->getGeneratedUrl(); } return $urls; } diff --git a/modules/stanford_publication/src/CitationViewBuilder.php b/modules/stanford_publication/src/CitationViewBuilder.php index 5038aaea..80686a64 100644 --- a/modules/stanford_publication/src/CitationViewBuilder.php +++ b/modules/stanford_publication/src/CitationViewBuilder.php @@ -97,8 +97,8 @@ protected function buildDateDisplay(array $build): array { $month['#label_display'] = 'hidden'; $day['#label_display'] = 'hidden'; - $month = (int) trim(strip_tags($this->renderer->render($month))); - $day = (int) trim(strip_tags($this->renderer->render($day))); + $month = (int) trim(strip_tags($this->renderer->renderPlain($month))); + $day = (int) trim(strip_tags($this->renderer->renderPlain($day))); if ($month) { $date = date('F', strtotime("1-$month-2000")); diff --git a/src/EventSubscriber/PreprocessEventSubscriber.php b/src/EventSubscriber/PreprocessEventSubscriber.php index d377a76d..a274b6ea 100644 --- a/src/EventSubscriber/PreprocessEventSubscriber.php +++ b/src/EventSubscriber/PreprocessEventSubscriber.php @@ -99,7 +99,7 @@ protected static function getTargetUrl(TrustedRedirectResponse $redirect_respons catch (\Exception $e) { $url = Url::fromUri($target_url, ['absolute' => TRUE]); } - return $url->toString(); + return $url->toString(TRUE)->getGeneratedUrl(); } diff --git a/src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php b/src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php index 9d03dc60..9e7e2cdc 100644 --- a/src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php +++ b/src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php @@ -25,7 +25,7 @@ class SimplePreview extends PreviewUrlGeneratorBase { public function generate(NextSiteInterface $next_site, EntityInterface $entity, string $resource_version = NULL): ?Url { return Url::fromUri($next_site->getPreviewUrl(), [ 'query' => [ - 'slug' => $entity->toUrl()->toString(), + 'slug' => $entity->toUrl()->toString(TRUE)->getGeneratedUrl(), 'secret' => $next_site->getPreviewSecret(), ], ]); diff --git a/stanford_profile_helper.module b/stanford_profile_helper.module index 4c20ea25..47fed8c4 100644 --- a/stanford_profile_helper.module +++ b/stanford_profile_helper.module @@ -156,7 +156,7 @@ function stanford_profile_helper_redirect_presave(EntityInterface $redirect) { */ function _stanford_profile_helper_purge_path($path) { $url = Url::fromUserInput('/' . trim($path, '/'), ['absolute' => TRUE]) - ->toString(); + ->toString(TRUE)->getGeneratedUrl(); $purgeInvalidationFactory = \Drupal::service('purge.invalidation.factory'); $purgeProcessors = \Drupal::service('purge.processors'); @@ -432,6 +432,7 @@ function stanford_profile_helper_preprocess_input__submit__paragraph_action(&$va */ function stanford_profile_helper_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) { if ( + $operation != 'view' && $field_definition->getName() == 'status' && $field_definition->getTargetEntityTypeId() == 'node' && $items && @@ -494,7 +495,7 @@ function stanford_profile_helper_contextual_links_alter(array &$links, $group, a function stanford_profile_helper_node_access(NodeInterface $node, $op, AccountInterface $account) { if ($op == 'delete') { $site_config = \Drupal::config('system.site'); - $node_urls = [$node->toUrl()->toString(), "/node/{$node->id()}"]; + $node_urls = [$node->toUrl()->toString(TRUE)->getGeneratedUrl(), "/node/{$node->id()}"]; // If the node is configured to be the home page, 404, or 403, prevent the // user from deleting. Unfortunately this only works for roles without the @@ -783,7 +784,7 @@ function stanford_profile_helper_preprocess_pattern_localfooter(&$variables) { $link = $entity->get('su_local_foot_loc_link')->getString(); if ($link) { $variables['lockup_link'] = [ - '#markup' => URL::fromUri($link)->toString(), + '#markup' => URL::fromUri($link)->toString(TRUE)->getGeneratedUrl(), ]; }