This is the same request as #621538: Switch to using Views to allow greater flexibility but for Drupal 7.

I currently have it working on a site. Will submit a patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cwithout’s picture

Here is the patch against dev for user Follow in views for D7.

Compatible with view 7.x-3.1. May not work with previous versions of Views. If testing, please include the version of Views you used so there's an accurate indication of which versions of Views this is compatible with.

The field to add to views is called "User Follow Links". It's added the same as any other field. If you want to add Follow links to a content View, make sure you have a user relationship, such as "Content: Author". If there's no user relationship, you won't have the "User Follow Links" field available.

modctek’s picture

I get "Hunk #1 FAILED at 1"

***************
*** 1,3 ****
  name = Follow
  description = Add sitewide and per user links to social network profiles.
  core = 7.x
--- 1,6 ----
  name = Follow
  description = Add sitewide and per user links to social network profiles.
  core = 7.x
+ 
+ ; Views handlers
+ files[] = views/follow_handler_user.inc
modctek’s picture

Manually patched the info file that failed above, was able to see the field to add it to a User view, but then got this message after adding the field:

The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.

This is with Views 7.x-3.3

cwithout’s picture

Status: Active » Needs review

I didn't realize I never set this to needs review.

modctek, I just tested, and yes it works with Views 7.x-3.3.

That sounds like the behavior if it's installed but the cache isn't flushed. Did you flush the cache after installing the patch?

I tried to reroll, but it doesn't make a difference. It seems to be conflicting with the Drupal packaging info that's added to the .info file. I'm not sure if there's some special treatment that needs to be done for Drupal .info files.

cwithout’s picture

FileSize
7.01 KB

FYI the patch doesn't have default views in it to provide the Views to replace the current blocks. It only has the handlers for users, not site. Default views can be added once the handlers have been tested and incorporated.

In case anyone isn't sure how to create the View, attached is an exported view that will provide a block that can be used on user pages as well node pages. On node pages, the follow links are for the node author. Adding follow links for node authors is functionality that the current block does not provide.

cwithout’s picture

Attached is a new patch with a few minor changes and additional features. Works with Follow 7.x-1.x-dev and Views 7.x-3.5.

  • Adds a filter on the rendered links field. With #1 patch, if a user had no links, the block would render with just the title. The filter allows for excluding the block on pages for users who don't have any links entered.
  • Adds the follow_links table as a base table and all its columns as available fields with sort and filter handlers.

I've also attached new sample views. The first 2 can be used as blocks on node pages to show node author follow links.

  • User Follow: Users is base table. It uses the field "User: Follow Links" which outputs the links fully themed. ("User: Follow Links" field requires Query Settings to have Distinct enabled and no other "Follow Links" fields. Can replace "User: Follow Links" field with other fields to customize.)
  • Follow User: Follow_links is the base table. The field is "Follow Links: Rendered Link". This outputs each link individually themed without the wrapper markup. Each field in the follow_links table can be added.
  • Site Follow: User table as the base to output the themed links. Fields can be changed for customization.
irk’s picture

I tested the patch with the sample views on simplytest.me. Everything worked and I got no errors. I can't do a deep code/security review, though. Is that needed?

Otherwise this is really great, looks like it could be very useful.

cwithout’s picture

Thanks for testing, irk.

The only files that would need review are the views handlers that were added. There views definitions in follow.views.inc just define how to handle the data.

follow.module : Moves existing code into a function follow_link_service_title() so it can be reused (instead of duplicated) in the views handler.

follow_handler_user.inc : Relies on the existing code to generate output, so doesn't introduce any new potential security issues. uses the existing follow_links_load() and follow_networks_load() functions and the outputs them using the follow_links themeing

follow_handler_filter_user.inc : Handles the user filter query, but doesn't add any user-input data to the query as well as uses views_plugin_query_default::add_where().

follow_handler_field_follow.inc : Also relies on the existing code. Uses follow_networks_load(), new follow_link_service_title() and the follow_link theming.

follow_handler_field_title.inc : Adds a views options form with a boolean checkbox. Also renders the output using existing code. follow_networks_load() and follow_link_service_title(). Uses the boolean result of the options form to determine whether to add a link from a value in that database using l(), which runs the path through check_plain().

Somebody who didn't write the code could look it over. It wouldn't hurt anything, but almost all output is using the existing functions in the module. The only piece of data that's not is the path being run through l().

SamuelChris’s picture

i'm know it

heliogabal’s picture

I tried to patch with 7.x-2.x-dev, Last updated: May 1, 2013 - 02:55 and views 3.7 and get the following:

patching file follow.info
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file follow.info.rej
patching file follow.module
Hunk #1 succeeded at 318 with fuzz 1 (offset 42 lines).
Hunk #2 FAILED at 325.
Hunk #3 succeeded at 633 (offset -274 lines).
1 out of 3 hunks FAILED -- saving rejects to file follow.module.rej
patching file views/follow.views.inc
patching file views/follow_handler_field_follow.inc
patching file views/follow_handler_field_title.inc
patching file views/follow_handler_filter_user.inc
patching file views/follow_handler_user.inc

follow.module.rej is:

--- follow.module
+++ follow.module
@@ -325,7 +335,7 @@
   $output = '<div class="follow-links clearfix">';

   foreach($links as $link) {
-    $title = !empty($link->title) ? $link->title : $networks[$link->name]['title'];
+    $title = follow_link_service_title($networks, $link);
     $output .= '<' . $wrapper . ' class="follow-link-wrapper follow-link-wrapper-' . $link->name . '">';
     $output .= theme('follow_link', array('link' => $link, 'title' => $title));
     $output .= '</' . $wrapper . '>';

unfortunately, I have no idea how to debug this... but I hope it is helpfull nevertheless, as this would be an awesome feature to have.

justawayfarer’s picture

I would love this feature too. I attempted to do this without touching code by using the Views block area module to select and place the "follow:user" block from the Follow Module in header or footer of views. Unfortunately, it would not display due to whatever restriction (understandable per module purpose) that was set up to have the follow user block display only on the users profile. The views integration this thread is hoping to see added is a great idea. If this integration is not important to the overall development of this module, would the maintainer q0rban (or other contributes) be willing to employ code alterations so that this module could work with this Views block area module. I wondered if it might be a simpler or lesser rewrite of code than a full blown views integration. Somewhat related to this is my attempt to use Block Reference module with the "follow:user" block. I was also only able to use it on the user profile but not in any other content type/node.

I wish I knew how to work with php, and understood the needed modifications. I'd help if I could. I greatly appreciate the incredible contributions of the Drupal community! Any help or thoughts!

Thanks!

cwithout’s picture

That's a good thought, justawayfarer. The Views integration doesn't require any rewrite of the existing module code though. It's just adding Views handlers that use the existing functions. So it's not possible to have a solution that requires any less of a rewrite.

Edit: Oh. There is one line that is moved into a function so it can be reused in the views handler. But the behavior itself remains the same.

Based on comment #10, the patch may no longer be compatible. I'd be happy to reroll the patch for the current version if a maintainer gives this issue any attention or acknowledgement that this feature request would be welcome.

justawayfarer’s picture

Thanks a bunch cwithout. That was helpful.

justawayfarer’s picture

I noticed the use of the follow:user block in an author blurb beside posted content at www.lullabot.com. So I started trying to see how they did it and discovered this implementation is from our module maintainer q0rban (www.lullabot.com/who-we-are/james-sansbury). The implementation is probably buried somewhere in their github repository https://github.com/Lullabot/drupalize-lullablog-user also dependent on https://github.com/Lullabot/drupalize-lullablog. I don't know enough about code to see how this works and if it is a views solution or something else, but thought I'd post it here for cwithout to take a peak if she's still interested in this. cwithout, have you thought of becoming a co-maintainer? It looks like q0rban is seeking co-maintainers for the follow module. In the mean time, I will probably just role my own follow links in a similar fashion to http://adaptivethemes.com/social-network-links-with-drupal-7-views-and-link. If I get time to learn php, I'd have a lot more value to add to the thread and this possible feature addition. I greatly appreciate the efforts of developers for these modules.

cwithout’s picture

Thanks, justawayfarer. I asked about co-maintainership and got no reply. The patch in this issue is functional and I've been using it on several of my own sites. It's basically ready to go, but with no response from the maintainer, I'm not willing to put more energy into it.

I think the follow module and views combination is the best/fastest way to add social follow links over setting up your own fields, etc and views. Adding views to follow makes it much more flexible. Unfortunately, it and several other aspects of the module which have contributions already completed by others are being ignored.

GotYourGuy’s picture

Thanks for the patch, cwithout! I got it to apply cleanly to the 7.x-1.x-dev version and after fixing a line in rules bonus pack I got it to work. This seemed like such obvious functionality to me I had a hard time believing I couldn't find it standard.

jemisond’s picture

Issue summary: View changes

I am definitely interested in a re-roll for 7.x-2! Having access through Views seems like a critical feature.

andrew@oscailte.org’s picture

On the latest version 7.x-2.0-alpha1, installing this patch gives:

patching file follow.info
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file follow.info.rej
patching file follow.module
Hunk #1 succeeded at 308 with fuzz 1 (offset 32 lines).
Hunk #2 FAILED at 325.
Hunk #3 succeeded at 626 (offset -281 lines).
1 out of 3 hunks FAILED -- saving rejects to file follow.module.rej
patching file views/follow.views.inc
patching file views/follow_handler_field_follow.inc
patching file views/follow_handler_field_title.inc
patching file views/follow_handler_filter_user.inc
patching file views/follow_handler_user.inc

I manually applied the changes to follow.info and ignored the failed Hunk #2 in follow.module. Appears to work fine, but I'm minimally using this module in a single view.

amaisano’s picture

That failed hunk target has been moved to follow.inc - you can manually apply that one change there if you want, instead of ignoring it. Not sure if it's relevant or not though, as things seemed to work fine ignoring that failure.

gausarts’s picture

I appreciate the work here.

However I would love to give my 2 cents.
If you have link module installed, Linkicon will be the easiest route than this 4-year-old fight.

Perhaps the maintainer could hand over this type of functionality to the module designed for this purpose? Thank you.