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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcarlson34’s picture

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

das-peter’s picture

Assigned: Unassigned » das-peter
Status: Fixed » Needs review
FileSize
1.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.

dawehner’s picture

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

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

jcarlson34’s picture

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.

ayalon’s picture

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.

rbosscher’s picture

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

mkinnan’s picture

I also confirm patch #5 worked for me.

grasmash’s picture

Works for me. Please commit?

merlinofchaos’s picture

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

grasmash’s picture

**IGNORE ** Attached wrong file.

grasmash’s picture

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

alxp’s picture

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?

dawehner’s picture

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

geerlingguy’s picture

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...

geerlingguy’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
FileSize
2.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...).

juves’s picture

It works for me with latest views dev

GiorgosK’s picture

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)

dawehner’s picture

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

geerlingguy’s picture

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

dawehner’s picture

Status: Fixed » Reviewed & tested by the community

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

merlinofchaos’s picture

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

geerlingguy’s picture

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

dawehner’s picture

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

geerlingguy’s picture

Attached patch for 6.x-3.x.

merlinofchaos’s picture

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.

geerlingguy’s picture

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.

kevin.mcnamee@mailbox.org’s picture

subscribing

kevin.mcnamee@mailbox.org’s picture

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

StG’s picture

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?

merlinofchaos’s picture

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.

merlinofchaos’s picture

Also committed this to 6.x-3.x

Status: Fixed » Closed (fixed)

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

asb’s picture

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!

mollyavalon’s picture

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.

asb’s picture

dthiessen’s picture

Status: Closed (fixed) » Active

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

dthiessen’s picture

Status: Active » Closed (fixed)

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

dawehner’s picture

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