- 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(&$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 (!isset($variables['items'][0]['content']['#title'])) { ...
?Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
. The suggestion ofif (null !== ($variables['items'][0]['content']['#title'])) {
didn't work either, if statement didn't check out.