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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost’s picture

Good idea so need work to make more configurable

mansspams’s picture

I would need this but cannot provide code.

andypost’s picture

@mansspams try code provided by @schibou

Guillaume Schieber’s picture

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

mansspams’s picture

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.

Guillaume Schieber’s picture

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.

andypost’s picture

@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

mansspams’s picture

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!

mansspams’s picture

Status: Needs work » Needs review

one more review?

mattiasj’s picture

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

skizzo’s picture

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

caschbre’s picture

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

andypost’s picture

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

andypost’s picture

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

skizzo’s picture

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

marcushenningsen’s picture

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.

andypost’s picture

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

marcushenningsen’s picture

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

DeFr’s picture

FileSize
1.47 KB

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

andypost’s picture

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

caschbre’s picture

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

DeFr’s picture

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

andypost’s picture

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

DeFr’s picture

FileSize
1.88 KB

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.

loominade’s picture

subscribing

andypost’s picture

Status: Needs review » Fixed
dicreat’s picture

Any solution to provide this count-fields for sorting in Views?
#663238: Option in Views to sort according to the count of referrers

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sotiris’s picture

Version: 6.x-1.x-dev » 6.x-1.0-rc1
Category: feature » support

Has this feature included in the latest 6.x-1.0-rc1? I have installed it but i can see only Node: Nodereferrer: by field, and Node: Nodereferrer: by node type, inside my views at the add fields section...

sotiris’s picture

Priority: Minor » Normal
andypost’s picture

Status: Closed (fixed) » Fixed

Yes you right, choosing one Node: Nodereferrer: by field or Node: Nodereferrer: by node type you can choose formatter for the field, the same at admin/content/node-type//display Display fields you can choose to display only count of referrers.

It could be good if someone help me to update docs about this.

sotiris’s picture

Thanks a lot for your help.

I used the second solution with display fields, and i've got my referrers counted. The only thing is that i got the following warning messages every first time that i call a node with the referrer field. When i called again the same node the warnings didn't appear.

The same warnings appeared again when i called other nodes with referrer field but only for the first time for every node.

warning: array_filter() [function.array-filter]: The first argument should be an array in /drupal-6.15/sites/all/modules/nodereferrer/nodereferrer.module on line 135.
warning: array_values() [function.array-values]: The argument should be an array in /drupal-6.15/sites/all/modules/nodereferrer/nodereferrer.module on line 135.
warning: array_filter() [function.array-filter]: The first argument should be an array in /drupal-6.15/sites/all/modules/nodereferrer/nodereferrer.module on line 136.
warning: array_values() [function.array-values]: The argument should be an array in /drupal-6.15/sites/all/modules/nodereferrer/nodereferrer.module on line 136.

andypost’s picture

Status: Fixed » Needs review
FileSize
1.11 KB

Please try this patch

sotiris’s picture

Status: Needs review » Fixed

After aplying your patch the warning messages doesn't appear any more.

Many thanks!

andypost’s picture

commited to HEAD and DRUPAL-6 so will be included in next release and -dev

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bg1’s picture

Does the patch mentioned here give any ability to sort the nodereferrer results by the title of the referring node?

If not, is there some way to do that so the view results will display sorted?

Thanks.

Stomper’s picture