Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm using a custom PHP field to get how many days since the last comment on a node. I have a relationship for "Last Comment" set up in the view. I'm using the following PHP code in the custom field:
$comment = strtotime($row->changed_1);
$daysPast = round((time() - $comment)/86400);
echo $daysPast;
This works fine for both the table view and the map as long as I display the Last Comment field; however, when I select: "Exclude from display" on the Last Comment field in the view, it stops working in the map. It still works fine in the table view, but the map view no longer retrieves $row->changed_1 properly to use in the custom PHP field.
Comments
Comment #1
RdeBoerHi Ryan,
Thank you for your report.
Are you using the "value" field in the Views PHP UI or the "output" field?
And which version of Views PHP?
Rik
Comment #2
ryantollefson CreditAttribution: ryantollefson commentedThanks RdeBoer, you set me on a workaround path...
I was using the Output field.
Views PHP 7.x-2.x-dev - but I think I'm on a build from at several months back.
Playing around with this a bit more, I was able to get it to work by using both the "value" field & the "output" field.
Value field (of course without php markers for the value field):
Output field:
This works great for what I need!
Still seems strange that it didn't work the other way (especially when the table view worked just fine). I still think there might be a bug here, but easy enough to work around. I'm fine with closing issue if we want, but it may pop up again for someone.
Comment #3
RdeBoerHi Ryan,
Great that you found and shared your workaround.
Views PHP is a bit of an odd bed fellow for Views, so can may the setup a bit finicky.
I'll mark it as "Needs work" -- but it may be some time before I work on it.
Rik
Comment #4
rcodina CreditAttribution: rcodina commented@ryantollefson Many thanks for sharing your workaround. It worked for me too!