How to get the url from a link field in preprocess function I have a content type event.
It has a link field field_event_location_link
Both the link text and url are optional


By default Drupal uses the url as the title if there is no title typed in. 

I want to show 'Location' if the title is not filled in.

How can I use a preprocess function to see if there is a title, and if not, use my string.

I tried ...

function my_module_preprocess_field(&amp;$variables) {
  if ($variables['field_name'] == 'field_event_location_link') {
    if ($variables['items'][0]['content']['#title'] == '') {
     $variables['items'][0]['content']['#title'] = 'Location';
    }
  }
}


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.

Question:
Can I catch it before that?
Or can I get a variable for the URL and use that variable in the '' above? Should I be checking if something is empty...?
If you inspect with $variables['items'][0]['content'] with Devel kint

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





  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']-&gt;toString();
    if ($variables['items'][0]['content']['#title'] == $link_url) {
      $variables['items'][0]['content']['#title'] = 'Location';
    }
  }