[Calendar Views] Replacement patterns don't work if referencing a field excluded from display
kcolbe - February 24, 2009 - 22:42
| Project: | Calendar |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Description
I have two fields I gather in a view. The first of which I don't want to be displayed (Node: Nid), I just want this so I can use it as a replacement pattern in my second field (Node: Title). So I checked of "exclude from display" on (Node: Nid). What I'd like to do is "rewrite the output" of the (Node:Title) field so I can create a custom link ie. /foo/bar/[nid] from it. [nid] (Node: Nid) is listed as an available replacement pattern but it returns a null value unless it is NOT "excluded from display".
| Attachment | Size |
|---|---|
| views_edit_date_browser.jpg | 308.97 KB |

#1
This is already fixed in -dev.
Also, active (needs more info) is used to indicate that the issue queue maintainers need info from the poster, so setting your issue to this status can cause it to be ignored.
#2
Thanks for your help. I cleared my cache, uninstalled the old views (using uninstall then removing the views dir), rebuilt menus (not that I think I'd have to for this), then updated to the latest dev version of views...but I still have the same problem. Please see the attached screenshots. Thanks.
#3
#4
What, you didn't think the fact that you're using a calendar style was relevant?
Especially with this in the release notes:
Please doublecheck this problem in a core Views style. If it doesn't appear there, then it's not a Views bug, and you should refile against calendar.
#5
Please see the above posts...
#6
#7
kcolbe: which version of PHP are you using?
Probably duplicate of: #442768: Replacement pattern [nid] doesn't work on PHP4
#8
Im using 5.2.6
#9
I've encountered exactly the same issue as original post -
I see a field disappears from output by replacement patterns if is checked "Exclude from display" with all the latest -dev versions:
Calendar 6.x-2.x-dev 2009-Jul-29
Views 6.x-2.x-dev 2009-Jul-27
Token 6.x-1.x-dev 2009-Jul-21
PHP 5.2.9
MySQL 5.0.67
Reopening. Also, raising priority because it makes calendar.module 99% useless for any of my sites.
#10
Patch is attached against Calendar 6.x-2.x-dev 2009-Jul-29.
I traced the problem to function template_preprocess_calendar() in theme/theme.inc. It erases the 'exclude'd field on the first pass through the fields. That makes the field not available for the subsequent replacement patterns in other fields. The patch changes it to two-pass, with 'exclude' in the second pass.
That fixes the problem for me. Please review for commit to -dev.
#11
I was uneasy about #1 by merlinofchaos, stating that it was already fixed in -dev, so I kept looking at the code in question, trying to understand why the fix I did actually makes a difference.
I noticed that there is a call to drupal_clone() used to create $copy that is passed to $field->theme($copy). I recognize the intent to operate on object's copy, so unset() that is called on the target 'exclude'd field will not affect pattern replacement. Should be working without my patch... Hm.
However, I followed into drupal_clone(), which in turn calls PHP 5 clone. Its doc page mentions (see http://us3.php.net/clone) "When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties. Any properties that are references to other variables, will remain references.". Maybe that was the culprit of the original code not working. If the fields are references, then unsetting it may affect the original.
I didn't have enough time to dig into that too much, but I can re-confirm the fact that the above patch indeed fixes the problem. If I remove the patch, the problem returns.
#12
The patch works for me. Thanks a lot.
For clarification (at least I didn't get that at first), the patch is to be applied against theme.inc in the mentioned calendar package.
#13
This patch works for me, and I need it. :-) Nice work, iva2k.
#14
Confirmed too. Patch #10 works.
#15
great... #10 works also for me :-) Thank you so much!
#16
Note: Marked #540388: rewrite fields do not show if field is set to exclude as a duplicate of this issue
#17
I can also confirm the #10 patch works.
#18
I confirm too, the #10 patch work for me, please integrate it on the release/dev.
many thanks iva2k.
#19
Thanks a million, iva2k. I appreciate the research into php5's object cloning behavior.
The patch at #10 does the trick for me (using Calendar 6.x-2.2 release).