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)

AttachmentSize
nodereferrer_view_handler_field.patch9.39 KB
nodereferrer_view_handler_field.inc.zip1.54 KB

#1

andypost - April 9, 2009 - 11:57

Good idea so need work to make more configurable

#2

mansspams - June 3, 2009 - 10:10

I would need this but cannot provide code.

#3

andypost - June 3, 2009 - 11:23

@mansspams try code provided by @schibou

#4

schibou - June 10, 2009 - 14:45

@mansspams the patch work's for me, you can try it.

#5

mansspams - June 11, 2009 - 07:04

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

schibou - June 16, 2009 - 15:49

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

andypost - June 17, 2009 - 14:54

@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

mansspams - July 12, 2009 - 20:29

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

mansspams - July 12, 2009 - 20:58
Status:needs work» needs review

one more review?

#10

mattiasj - August 25, 2009 - 12:35

I would really need this functionality as well, thanks for the patch.

#11

skizzo - September 19, 2009 - 09:52

After applying the patch the feature works properly for me. Thank you.

#12

caschbre - September 21, 2009 - 22:55

I'm interested in this functionality. How would I go about applying the supplied patch?

#13

andypost - September 22, 2009 - 09:50

@caschbre try docs at http://drupal.org/patch/apply

#14

andypost - September 22, 2009 - 10:04

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

skizzo - October 20, 2009 - 06:45

looks like the OP patch does not apply to nodereferrer 6.x-1.0-beta2 dated 2009-09-22

#16

marcushenningsen - October 29, 2009 - 12:25

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

andypost - October 29, 2009 - 17:39

Glad to commit if someone provide a patch against DRUPAL-6 but not replacing existing features

#18

marcushenningsen - October 30, 2009 - 09:51

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

DeFr - November 19, 2009 - 10:37

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:

  • Node: Nodereferrer: by field
  • Node: Nodereferrer: count by field
  • Node: Nodereferrer: by type
  • Node: Nodereferrer: count by type

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

AttachmentSize
416332.patch 1.47 KB

#20

andypost - November 19, 2009 - 15:03

@DeFr this approach looks great! need more reviews and I glad to commit this!

#21

caschbre - November 19, 2009 - 15:19

I'm interested in helping to test this. Do I just install the dev version and then apply the patch?

#22

DeFr - November 19, 2009 - 16:37

@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

andypost - November 19, 2009 - 17:45

Suppose we need a new formatter for cck display not only for views and update docs

#24

DeFr - November 19, 2009 - 19:10

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.

AttachmentSize
416332-24.patch 1.88 KB
 
 

Drupal is a registered trademark of Dries Buytaert.