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

AttachmentSize
views_edit_date_browser.jpg308.97 KB

#1

merlinofchaos - February 24, 2009 - 23:27
Status:postponed (maintainer needs more info)» fixed

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

kcolbe - February 25, 2009 - 18:51
Status:fixed» active

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.

AttachmentSize
views_edit_date_browser.jpg 247.42 KB
admin_reports_updates.jpg 146.98 KB

#3

kcolbe - February 25, 2009 - 18:54
Version:6.x-2.3» 6.x-2.x-dev

#4

merlinofchaos - February 25, 2009 - 19:32
Status:active» postponed (maintainer needs more info)

What, you didn't think the fact that you're using a calendar style was relevant?

Especially with this in the release notes:

A minor change in the API now requires that styles that render fields MUST
render them in order, first by row and then by field ID. Not doing so will
cause the token expansion to fail.

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

kcolbe - February 25, 2009 - 23:36
Title:Replacement patterns don't work if referencing a field excluded from display» [Calendar Views] Replacement patterns don't work if referencing a field excluded from display
Project:Views» Calendar
Version:6.x-2.x-dev» 6.x-2.x-dev
Component:Views Data» Code

Please see the above posts...

#6

kcolbe - February 25, 2009 - 23:37
Status:postponed (maintainer needs more info)» active

#7

kenorb - May 18, 2009 - 13:56

kcolbe: which version of PHP are you using?
Probably duplicate of: #442768: Replacement pattern [nid] doesn't work on PHP4

#8

kcolbe - May 18, 2009 - 16:56
Status:active» closed

Im using 5.2.6

#9

iva2k - July 31, 2009 - 15:37
Priority:normal» critical
Status:closed» active

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

iva2k - August 1, 2009 - 17:59
Status:active» needs review

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.

AttachmentSize
calendar.field_exclude20090801.patch 1.25 KB

#11

iva2k - August 7, 2009 - 07:02

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

marcushenningsen - August 7, 2009 - 23:01

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

ZoeN - August 11, 2009 - 07:24
Status:needs review» reviewed & tested by the community

This patch works for me, and I need it. :-) Nice work, iva2k.

#14

felipe - September 3, 2009 - 23:17

Confirmed too. Patch #10 works.

#15

pyzahl - September 16, 2009 - 11:43

great... #10 works also for me :-) Thank you so much!

#16

arlinsandbulte - September 16, 2009 - 12:17

Note: Marked #540388: rewrite fields do not show if field is set to exclude as a duplicate of this issue

#17

TwoD - September 24, 2009 - 20:45

I can also confirm the #10 patch works.

#18

mentat.fr - October 21, 2009 - 10:00

I confirm too, the #10 patch work for me, please integrate it on the release/dev.
many thanks iva2k.

#19

mysterlune - November 1, 2009 - 20:54

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

 
 

Drupal is a registered trademark of Dries Buytaert.