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
Comment #1
jcarlson34 CreditAttribution: jcarlson34 commentedTurns 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
Comment #2
das-peter CreditAttribution: das-peter commentedI'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.Comment #3
dawehnerThis might should be added to 6.x-3.x, too
Comment #4
jcarlson34 CreditAttribution: jcarlson34 commentedThank 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.
Comment #5
ayalon CreditAttribution: ayalon commentedI 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.
Comment #6
rbosscher CreditAttribution: rbosscher commentedI can confirm patch #5 works.
I agree with Ayalon, this is incredible useful!!
Comment #7
mkinnan CreditAttribution: mkinnan commentedI also confirm patch #5 worked for me.
Comment #8
grasmash CreditAttribution: grasmash commentedWorks for me. Please commit?
Comment #9
merlinofchaos CreditAttribution: merlinofchaos commentedThere is a misspelling in the patch that prevents it from being RTBC. Can anyone reroll?
Comment #10
grasmash CreditAttribution: grasmash commented**IGNORE ** Attached wrong file.
Comment #11
grasmash CreditAttribution: grasmash commentedI fixed the misspelling in the description row. Is that what you were referring to?
Comment #12
alxp CreditAttribution: alxp commentedThe 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?
Comment #13
dawehnerOne thing is to test the patch and review it. See http://drupal.org/node/156119 for the different issue status.
Comment #14
geerlingguy CreditAttribution: geerlingguy commentedSubscribe - 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...
Comment #15
geerlingguy CreditAttribution: geerlingguy commentedGit 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...).
Comment #16
juves CreditAttribution: juves commentedIt works for me with latest views dev
Comment #17
GiorgosK#11 works for me for 6.x 3.x dev
(thought #15 is only for 7.x version)
Comment #18
dawehnerThanks for providing and testing the patch.
Code looks fine as always. Commited to 7.x-3.x
Comment #19
geerlingguy CreditAttribution: geerlingguy commentedAre you sure this was committed? I couldn't find it in the commit logs...
Comment #20
dawehnerTrue, mh perhaps i forgot to push it, update status.
Comment #21
merlinofchaos CreditAttribution: merlinofchaos commentedI think the text should be: "Do not rewrite if empty" with no #description.
Comment #22
geerlingguy CreditAttribution: geerlingguy commentedRemoved description, changed the text to "Do not rewrite if empty." Makes more sense, and even looks nicer...
Comment #23
dawehnerCan someone make an updated patch for 6.x-3.x as well? This would be cool
Comment #24
geerlingguy CreditAttribution: geerlingguy commentedAttached patch for 6.x-3.x.
Comment #25
merlinofchaos CreditAttribution: merlinofchaos commentedThe 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.
Comment #26
geerlingguy CreditAttribution: geerlingguy commentedI 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.
Comment #27
kevin.mcnamee@mailbox.org CreditAttribution: kevin.mcnamee@mailbox.org commentedsubscribing
Comment #28
kevin.mcnamee@mailbox.org CreditAttribution: kevin.mcnamee@mailbox.org commentedThe 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
Comment #29
StG CreditAttribution: StG commentedHello,
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?
Comment #30
merlinofchaos CreditAttribution: merlinofchaos commentedIt appears dereine committed this at the beginning of June. I followed up with kmcnamee's text change suggestion.
Comment #31
merlinofchaos CreditAttribution: merlinofchaos commentedAlso committed this to 6.x-3.x
Comment #33
asb CreditAttribution: asb commentedIs 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!
Comment #34
mollyavalon CreditAttribution: mollyavalon commentedI 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.
Comment #35
asb CreditAttribution: asb commentedF'up issue for 6.x-2.14: #1331032: Empty rewritten fields are not hidden anymore
Comment #36
dthiessen CreditAttribution: dthiessen commentedSame issue with 6.x-2.14. Worked great before the update.
Comment #37
dthiessen CreditAttribution: dthiessen commentedJust noticed the new issue for the fix. Marking this as closed again.
Comment #38
dawehnerCommited to 6.x-2.x as well, see http://drupal.org/node/1331032#comment-5200454