Option in views to only display the number of referrers node ( count the child node of a cck node and display the number )
schibou - March 28, 2009 - 01:49
| Project: | NodeReferrer |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I needed to display the number of referrers node for some cck node in a page that I was creating using a view.
I used this module to link the referrers node but I only needed there number, not a list of them.
So I edited: nodereferrer_view_handler_field.inc to add a drop down menu to enable this feature.
I get it to works but it's not nicely integrated at all so, if someone else want this feature ported into the module, it will be nice to have it in a final release.
(Still I've put my modified nodereferrer_view_handler_field.inc file for the 6.x-1.x dev and the patch with this request)
| Attachment | Size |
|---|---|
| nodereferrer_view_handler_field.patch | 9.39 KB |
| nodereferrer_view_handler_field.inc.zip | 1.54 KB |

#1
Good idea so need work to make more configurable
#2
I would need this but cannot provide code.
#3
@mansspams try code provided by @schibou
#4
@mansspams the patch work's for me, you can try it.
#5
installed module, applied patch (replaced file from zip to be precise), added cck field, adjusted display (no count possibility there), tested how node looks, yes, nodes that refers to one i am looking at are displayed, so far so good. but in views i cannot find NodeReferrer field under content and got stuck there. I wonder what did i do wrong.
#6
Hum I don't know why, maybe some chages in recent versions that make it obsolete.
It was not ported into the module (since it was just a one time application), sorry it didn't work for you.
#7
@schibou try to make a patch against current HEAD, I've made some cleanup
This feature is great! I glad to include this into upcoming release
#8
i found the problem. i was looking under content but it is under node, so yes, @schibou patchs works and you may include it in future releases. thanks guys!
#9
one more review?
#10
I would really need this functionality as well, thanks for the patch.
#11
After applying the patch the feature works properly for me. Thank you.
#12
I'm interested in this functionality. How would I go about applying the supplied patch?
#13
@caschbre try docs at http://drupal.org/patch/apply
#14
Requested filter to list nodes without referrers #582034: Integrate referrer count in views2
Suppose we need filter and formatter. Filter in count expression and formatter to display counts
#15
looks like the OP patch does not apply to nodereferrer 6.x-1.0-beta2 dated 2009-09-22
#16
Might be that the patch doesn't work, but just copying nodereferrer_view_handler_field.inc into its place worked for me.
Thanks for this great feature. I used to make a forum with discussions with content types and views2.
I suggest you turn this feature into a separate field, enhances usability in my opinion.
#17
Glad to commit if someone provide a patch against DRUPAL-6 but not replacing existing features
#18
I'm afraid my php skills aren't sufficient to make a decent patch, but I'd love to help out in any way I can.
As I suggested above I'd prefer this feature in a separate handler: nodereferrer_view_handler_field_count.inc. This new handler should extend views_handler_field_numeric instead of views_handler_field since we are dealing with a numeric field.
andypost: I see that you've split up the handlers (nodereferrer_view_handler_field.inc, nodereferrer_view_handler_field_field.inc and nodereferrer_view_handler_field_type.inc), but I don't understand why? I don't know how much of the code should go into the new handler, since I don't really get what's going on in the code. Could you somehow lead me in the right direction?
Thanks
Marcus
#19
First of all, attaching a re-roll of the patch in this issue against the latest dev, and formatting it as a "real" patch.
@marcushenningsen in #18: the problem with that approach is that you'll need to duplicate pretty much all of the current code. Right now, nodereferrer_views_handler_field deals with common nodereferrer functions (as in, actually getting referrers, formatters options, stuff like that), and then both nodereferrer_views_handler_field_field and nodereferrer_views_handler_field_type inherits from that, and just customize the options form to let you select either specific fields or specific node types.
As a class can't have more than one parent in PHP, to have a class that extends views_handler_field_numeric, you'd need to implement the nodereferrer_views_handler_field_count handler, which would be mostly a copy of nodereferrer_views_handler_field with a rewritten render query, but then you'll *also* need to reimplement both nodereferrer_view_handler_field_field_count and nodereferrer_view_handler_field_type_count to base them on that new handler class. That's quite a lot of code duplication.
Supposing its done like that though, there would be two new fields in Views Field UI, resuling in something like:
That might be a bit easier on the end user, but that would also be a patch a lot bigger than the one attached.
@andypost: I guess it's your call :-)
#20
@DeFr this approach looks great! need more reviews and I glad to commit this!
#21
I'm interested in helping to test this. Do I just install the dev version and then apply the patch?
#22
@caschbre: Yes. After applying the patch, you'll see a new option appearing in the field setting forms, Display referrers count:, defaulting to No. Switch it to Yes and the field will then display the referrers count instead of the referrers list.
#23
Suppose we need a new formatter for cck display not only for views and update docs
#24
Rerolled with the count option as a field formatter instead of a view option. This approach upside is that it can be used everywhere and it doesn't add complexity to the Views field form: there's now a new option in the display as select instead, which means that you can choose to display the referrers as Node title, Node body... or Node count.
There's one downside though: Views easily let you alter the output a bit, which means the administrator can turn use this number in a sentence with one click on a case by case basis. It's not that easy in CCK land: developers will need to override the theme function, but that'll be site wide.
As it makes the code slightly prettier and it may be useful as a formatter nevertheless, I think I like this CCK field formatter approach best despite this problem though.