The "Hide if empty" option for works great for hiding empty fields, however this doesn't seem to extend to the Rewriting section. If I include text or html with the field token using "Rewrite the output of this field" or "Output this field as a link", the text or html still ends up being displayed while the token is hidden. It would be great to have an option to hide the rewrite if the the field is empty.

Example:

Let's say I have a text field for Twitter usernames. I add this field to my view and get the token [entity_id] == Fields: field_twitter_username. I then want to "Output this field as a link". I put http://www.twitter.com/[entity_id]. If the field_twitter_username field is empty, http://www.twitter.com/ will still be displayed while the token is hidden.

If there is a way to do this already I haven't figured it out yet or been able to enter the correct keywords into a search to find a solution. Thanks in advance for any help and thoughts.

Comments

Status:Active» Fixed

Turns out there's a way to do this (although it seems a little hacky it still works).

In case other people come across this post and wonder how to accomplish similar functionality, the answer is here: http://drupal.org/node/854002

Assigned:Unassigned» das-peter
Status:Fixed» Needs review
StatusFileSize
new1.95 KB

I've the same requirement, and the "link hack" seems not to work for all scenarios.
Thus I've created attached patch. It needs definitely review since I've no clue if $alter['rendered']['#markup'] is really always available and suitable for this purpose.

Version:7.x-3.x-dev» 6.x-3.x-dev

This might should be added to 6.x-3.x, too

Thank you for the patch das-peter. I will test it out and report back.

This feature has the potential to be an incredibly useful addition to Views.

I tested this patch and it is not working unless you correct an error in the code.

Attached you will find a working patch.

This feature ist incredible useful. Please review it.

I can confirm patch #5 works.
I agree with Ayalon, this is incredible useful!!

I also confirm patch #5 worked for me.

Works for me. Please commit?

There is a misspelling in the patch that prevents it from being RTBC. Can anyone reroll?

**IGNORE ** Attached wrong file.

I fixed the misspelling in the description row. Is that what you were referring to?

The patch in #11 fixed the problem for me. I'd like to see this committed, is there anything that needs to be done to move this along?

One thing is to test the patch and review it. See http://drupal.org/node/156119 for the different issue status.

Subscribe - I might write this up as a patch against the 7.x-3.x branch as well, as that's where I need the functionality. Seems simple enough...

Version:6.x-3.x-dev» 7.x-3.x-dev
StatusFileSize
new2.06 KB

Git patch attached (tested and working), for 7.x-3.x branch. Bumping issue to 7.x-branch, as that's the current dev branch. But the patch in #11 should also work perfectly. I'm not sure what the normal protocol is for this (6.x vs. 7.x patches...).

It works for me with latest views dev

Status:Needs review» Reviewed & tested by the community

#11 works for me for 6.x 3.x dev
(thought #15 is only for 7.x version)

Status:Reviewed & tested by the community» Fixed

Thanks for providing and testing the patch.

Code looks fine as always. Commited to 7.x-3.x

Are you sure this was committed? I couldn't find it in the commit logs...

Status:Fixed» Reviewed & tested by the community

True, mh perhaps i forgot to push it, update status.

I think the text should be: "Do not rewrite if empty" with no #description.

StatusFileSize
new1.97 KB

Removed description, changed the text to "Do not rewrite if empty." Makes more sense, and even looks nicer...

Can someone make an updated patch for 6.x-3.x as well? This would be cool

Attached patch for 6.x-3.x.

The test has gotten pretty ugly. This patch is ok to go in, but I would like to see if we can streamline that test so it's less brittle if we make additional changes.

I don't see much of a way to make it simpler, really :-/ Maybe split it out into the 'hide if empty' options, and to the 'if zero' separate, but that's about it.

subscribing

The field descriptions need more work. At a minimum the the help text should read:

To hide rewritten content, check the "Do not rewrite if empty" checkbox.

instead of

To hide rewritten content, check the Hide rewriting if empty checkbox.

Also, a description of the new field should be included (all other fields have a description). Something like:

Skip all rewriting actions if the field is empty.

/Kevin

Hello,

as far as I see, with this patch the field always returns an empty value. How would it be possible to show the text (html, field tokens whatever) from the "Empty text" field?

Status:Reviewed & tested by the community» Fixed

It appears dereine committed this at the beginning of June. I followed up with kmcnamee's text change suggestion.

Also committed this to 6.x-3.x

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Is it possible that this issue was introduced into 6.x-2.14 without the fix mentioned in #30?

At least for me it was possible to hide the contents of a rewritten field before I upgraded from 6.x-2.12 to 6.x-2.14. Please advise if this is a new issue and/or how this is supposed to be handled. Thanks!

I am having the same problem following upgrade this morning to 6.x-2.14. My rewritten fields are no longer hidden if empty. I was planning on upgrading my other sites tonight, but I think I will hold off.

Status:Closed (fixed)» Active

Same issue with 6.x-2.14. Worked great before the update.

Status:Active» Closed (fixed)

Just noticed the new issue for the fix. Marking this as closed again.

Commited to 6.x-2.x as well, see http://drupal.org/node/1331032#comment-5200454