attached is a handy little include file that adds views support to the links module. Display link title, link url (clickable as url, title, or the word [link]), and link clickthroughs in any view.

Comments

eaton’s picture

StatusFileSize
new543 bytes

Annnnnd the patch to links.module that includes it if views.module is installed.

RayZ’s picture

Mostly looks good, though I have one problem. I created a few weblink nodes and set up a view that is filtered by node type = weblink with each of the 3 link fields displayed in a table. The problem is that it is not listing the link titles. Apparently, it's looking for the link_title field in the links_node table (empty in my case) instead of the links table.

jvandervort’s picture

+1 for this feature request.

eaton’s picture

StatusFileSize
new2.58 KB

This version of links_views.inc corrects the issue with display of local and global link titles. Since the population of each field depends on a given site, there are now three handlers for the link_url: display as URL, display as local title, and display as global title. Should take care of your problem with the blank titles.

eaton’s picture

Status: Needs review » Reviewed & tested by the community
syscrusher’s picture

Assigned: Unassigned » syscrusher
Status: Reviewed & tested by the community » Needs review

I've committed the initial version of links_views.inc, and the small modification to links.module, into CVS tonight. Overall it looks nice, but there are a couple of things I'd like to open for discussion.

First, I don't think local vs. global link titles really belong as separate fields, and I've held off committing the "_0" version of the new .inc file for now. The way these fields work in the Links Package itself is that the global title is used if the local title is absent and ignored if the local title is present. I believe we should make the views support respect this behavior. However, I'm not a wizard with Views, so I wanted to throw this topic up to you for discussion rather than making a unilateral decision. Where does the $data parameter for your functions come from? How are the entries from the {links} and {links_node} tables being obtained in Views? We probably should be offering just the link title field and letting links.inc sort out *which* title to expose for any given node.

Second, there is some oddness (to my untrained eye) in the handling of nodes with multiple links. How were you intending this to behave? I am seeing separate entries in the view for each link of each node. Is that what you wanted...that the view behaves as if it is showing the link listing and the nodes are just (conceptually) containers for the links, when these fields are used? That is a perfectly reasonable (and probably useful) way to do things, but I want to make sure it is a decision and not an accident. :-)

Eaton, I'd welcome commentary from you and RayZ about the conceptual behavior of what you want to accomplish. In the meantime, I thank you for the contrib and have posted almost all of your code into CVS. There is no question in my mind that we want this feature -- I'm not meaning to criticize your work in any way. I just want to better understand the design of your code and how it fits into the rest of the Links Package.

Thanks again for the contrib!

Scott

eaton’s picture

Syscrusher, thanks for the response. I definitely see your point about local vs. global link titles. Your method (display the local title if it's available and the global title if it's not) should be very easy to implement. I can make that change this evening.

Regarding the multiple-line-items-per-node, that behavior was intentional. Each link is a separate record, at Views.module demonstrates the same kind of behaviour with taxonomy or amazon-node driven views, all of which can have multiple records associated with a node. For normal use of the weblinks.module, though, most users will never encounter the issue, and it will allow them to create 'slice and dice' browsable weblink archives via views.module.

Additional benefits of having each link treated separately (rather than concantenated together into a single field):

  1. A links page can list every URL that's been mentioned on the site, regardless of what node it was posted on. The 'recognize links in the body of each node' setting links.module offers makes this even more powerful.
  2. With creative use of Views, it's possible to list a node's linked URLs on a separate tab, like www.example.com/node/1/links, or to easily display them in a sidebar block.

Listing ALL the links associated with a node in one field (as one might want to do in a node listing) is possible with the views module, but if it's done, I think it would probably be best to put that in a separate field as far as views is concerned. 'All associated links', or something like that.

Obviously, I could be wrong ;) But that's what I had in mind when I put the .inc together.

eaton’s picture

StatusFileSize
new3.2 KB

Here's a patch that changes the field behavior: now, there's a single 'Link title' field that displays the local title if it's available, and the global title if there's no local one. The handlers have been changed a bit, so that link titles can be shown as clickable links or plain text.

It's not ready for prime time, but below is an example of the sort of stuff that's possible with it: this view definition shows all the attached links for a node in a separate tab, rather than below the body of the node.

<code>  $view = new stdClass();
  $view->name = 'node_links';
  $view->description = 'a tab listing all links associated with a node';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'table';
  $view->url = 'node/$arg/links';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '20';
  $view->menu = TRUE;
  $view->menu_title = 'links';
  $view->menu_tab = TRUE;
  $view->menu_tab_default = FALSE;
  $view->menu_weight = '';
  $view->sort = array (
  );
  $view->argument = array (
    array (
      'type' => 'nid',
      'argdefault' => '1',
      'title' => '',
      'options' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'links_node',
      'field' => 'link_title',
      'label' => 'title',
      'handler' => 'links_handler_field_title_clickable',
    ),
    array (
      'tablename' => 'links_node',
      'field' => 'clicks',
      'label' => 'clicks',
    ),
  );
  $view->filter = array (
  );
  $view->requires = array(links_node);
  $views[$view->name] = $view;

eaton’s picture

StatusFileSize
new3.83 KB

Ehhhh, here's a patch with a few typos and some terminology cleaned up (always use 'link' instead of 'weblink,' etc.)

jvandervort’s picture

Any news on a CVS update for this patch?
+2

syscrusher’s picture

Status: Needs review » Reviewed & tested by the community

Good evening, all! This is now committed to CVS. I did a brief test, and all seems well, but please retest your specific use-cases at your convenience.

Thanks for the contribs, folks!

Syscrusher

RayZ’s picture

Status: Reviewed & tested by the community » Fixed

Since this is now in CVS, I suppose this can be marked as fixed and new issues can be created as they come up (such as http://drupal.org/node/74763).

Anonymous’s picture

Status: Fixed » Closed (fixed)