Skip to content

Commit

Permalink
Fix urls in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Dec 15, 2023
1 parent 76d56ed commit bf15739
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion modules/jumpstart_ui/jumpstart_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function renderClean($elements, $tags = '<drupal-render-placeholder>') {
}

// 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, '<drupal-render-placeholder>')) {
$tags .= '<drupal-render-placeholder>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/stanford_events/stanford_events.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/stanford_publication/src/CitationViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
2 changes: 1 addition & 1 deletion src/EventSubscriber/PreprocessEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
],
]);
Expand Down
7 changes: 4 additions & 3 deletions stanford_profile_helper.module
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
];
}

Expand Down

0 comments on commit bf15739

Please sign in to comment.