Hello,

I'm trying to display link fields, and I need url and title separately.

If the title (optional) isn't filled in, Link module puts the url in place of the title.
But how to know if the title has been filled in or not, from a node template?

I can't find a way to check the real value of the title field.

Any idea?

Thanks!

Comments

jcfiala’s picture

Well, I'm not sure if this is a _bug_, actually, but that's a good point. Hm.

What if I returned some sort of 'title_status' field... or entered_title... thoughts?

jcfiala’s picture

You know, I think I might try returning an "original_title" and "original_url" fields, so themers can get at the original values if they __really__ want to... But willing to entertain feedback.

ludo.r’s picture

Category: bug » feature

In fact, I have a link field with optional title.

If the user fills in the title, then we display the title value.
If the user doesn't fill in the title, then we have to display "Read article", and it must be translated (so field's default value doesn't meet requirements).

"original_title" and "original_url" (?), seem to be a decent solution.

jcfiala’s picture

I'm thinking of combining this with #1475790: Link should not modify $item['url'] on node_view() (causes data loss when combined with Workbench Moderation), so that would mean actually going to creating new url/title/attribute fields for the themes to hook off of, and leaving the original url/title as is.

However, that's a bit of whiplash for existing theme functions. I'm thinking if I'm doing something this radical to how the field is themed, it should be part of moving to 7.x-2.0 version.

mile23’s picture

Title: How to know if the title field is empty? » Mark the anchor tag as having no title
Version: 7.x-1.0 » 7.x-1.x-dev
Category: Feature request » Bug report
Issue summary: View changes
Issue tags: +Novice

I'm going to call this a bug, since there is a common use-case where you wrap a link around a div that has an image, to provide a 'button' or what-have-you.

In that case, you'd want to leave the URL in place of the title for accessibility reasons, but be able to style the title text to hide it.

If someone wanted to do this, they'd alter theme_link_formatter_link_default() so that if there was no title field value, the link options attributes would contain a class called something like 'link-without-title'.

Then they'd write a test which adds a link with no title, and checks that it has the class added by l().

Adding Novice tag.

mile23’s picture

Just a heads-up: You can find the original title in the helpful original_title field.