Skip to main content
added 127 characters in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

If you inspect with $variables['items'][0]['content'] with Devel kint

kint($variables['items'][0]['content']);

enter image description here

But it doesn't work and I think it's because by the time I get to that point, Drupal has already used the uri for the #title.

Correct, so all you gotta do is check if the title is equal to the url utilizing Url::toString.

  if ($variables['field_name'] == 'field_event_location_link') {
    $link_url = $variables['items'][0]['content']['#url']->toString();
    if ($variables['items'][0]['content']['#title'] == $link_url) {
      $variables['items'][0]['content']['#title'] = 'Location';
    }
  }

If you inspect with $variables['items'][0]['content'] with Devel kint

kint($variables['items'][0]['content']);

enter image description here

But it doesn't work and I think it's because by the time I get to that point, Drupal has already used the uri for the #title.

Correct, so all you gotta do is check if the title is equal to the url.

  if ($variables['field_name'] == 'field_event_location_link') {
    $link_url = $variables['items'][0]['content']['#url']->toString();
    if ($variables['items'][0]['content']['#title'] == $link_url) {
      $variables['items'][0]['content']['#title'] = 'Location';
    }
  }

If you inspect with $variables['items'][0]['content'] with Devel kint

kint($variables['items'][0]['content']);

enter image description here

But it doesn't work and I think it's because by the time I get to that point, Drupal has already used the uri for the #title.

Correct, so all you gotta do is check if the title is equal to the url utilizing Url::toString.

  if ($variables['field_name'] == 'field_event_location_link') {
    $link_url = $variables['items'][0]['content']['#url']->toString();
    if ($variables['items'][0]['content']['#title'] == $link_url) {
      $variables['items'][0]['content']['#title'] = 'Location';
    }
  }
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

If you inspect with $variables['items'][0]['content'] with Devel kint

kint($variables['items'][0]['content']);

enter image description here

But it doesn't work and I think it's because by the time I get to that point, Drupal has already used the uri for the #title.

Correct, so all you gotta do is check if the title is equal to the url.

  if ($variables['field_name'] == 'field_event_location_link') {
    $link_url = $variables['items'][0]['content']['#url']->toString();
    if ($variables['items'][0]['content']['#title'] == $link_url) {
      $variables['items'][0]['content']['#title'] = 'Location';
    }
  }