Hi Peter,

I've added in some table drag support on the overview page so that the ordering of related content is user-definable, using the same mechanism as Drupal Menu module uses. There is currently no way to change the order in which related content appears, unless I guess you use Views in some way? Unless I've overlooked something?

Anyway I noticed that the ordinal_number isn't actually very important, as long as nodes that are related are ordered in some way - the values might be 1,2,3 or 1,45,235 for all it matters.

I've only modified a couple of functions to add in the table drag functionality.

Would this be a useful addition? If so, how do I supply my changes?

Ian.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vir_2’s picture

Hi Ian,

I'm very interested in this feature.

Can you please post your patches?

cheers,

volker

peter-boeren’s picture

Hello Ian,

that is most welcome. Maybe you can archive the module and send it by e-mail or attach it to a post. The D5 version had the possibility to add weights but I never had enough time to dig into the drag and drop functionality myself. I'm looking forward to your contributions.

Peter

Leumas’s picture

Hello

I think I found a solution to have custom ordered nodes for RelatedContent. It doesn't require any change on the module. Instead it uses another module to achieve the desired result of having drag and drop to order RelatedContent nodes.

The extra module I'm using is called DraggableViews. Very briefly this module allows you to order nodes from a view using drag and drop. Since in RelatedContent "the selected nodes are decoupled from the source from which they were selected" (see documentation section Decoupling) you can first specify a node order for the view and then select the related nodes. Even if you reorder the view afterwards, RelatedContent will display related nodes ordered as specified the first time.

I tried this for only a couple of hours and it seems to work quite well for what I need: a newsletter (using Simplenews) with a list of related custom ordered nodes. I created a view that lists my articles. Then I dragged and dropped the nodes to specify a display order. Finally I created a newsletter and selected the nodes I want to send using RelatedContent.

So I guess I'll use this new method for my next month newsletter.

Cheers,

Sam

ian-g’s picture

Sorry for the delay, being Christmas and all.

I've updated my changes to work on the current release (I had base-lined it from a July 2009 release).

I'm not sure how to create a patch file to work across 2 files (I've modified the .module and .theme.inc files), so I just attach them both here.

I'm sure there is a better way of doing some of my changes, but feel free to modify anything, and maybe incorporate into a new release at some point.

The interesting functions that I've changed are identified with my username (ian-g) so a simple diff on the current release and my modified file should highlight the changes. Essentially I change the functionality slightly if its the overview page...

cheers,

Ian.

peter panes’s picture

This would be exactly what i need but i cant get it to save, the drag and drop works but when i hit update all the related nodes disappear.

ian-g’s picture

Hi Peter,

I'm just about to install this module on a new site here, so I'll check it out and make sure I didn't miss anything when I uploaded my tweaks...

I'll report back later today.

Ian.

ian-g’s picture

I've just deployed this to a new site I'm working on, and it all worked fine.

I do display the related nodes in the right sidebar via a custom theme function, but my block is based on the more advanced example given in the documentation. I paste my custom block below, and attach the full module with my tweaks.

  if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
  $host_node = node_load($nid);
  $grouped = relatedcontent_variable_output_grouped($host_node->type);
  if($groups = relatedcontent($host_node, $grouped)) {
    foreach($groups as $group => $nodes) {
      if ($nodes) {
        $links = array();
        $snippets = array();
        foreach($nodes as $node) {
          $links[] = l($node->title, "node/$node->nid");
          // get my custom CCK field for this content type
          $snippets[] = $node->field_related_items_snippet[0]['value'];
        }
        print mythemehere_relatedcontent($links, $snippets);
      }
    }
  }
}  
peter-boeren’s picture

thanks ian-g for the effort. For me the holidays were also a break for Drupal. I'll look into it a soon as I have some open-source-spare-time.

to be continued!

peter panes’s picture

I have uninstalled the module completely and reinstalled with the 2 additional files. I still have the same problem, on attempting to save the new order by clicking the Update button, it empties the relatedcontent table and the related nodes are lost.

I have no idea whats going wrong.

peter panes’s picture

I have found the following error, i assume its something to do with my version of MySQL, any ideas:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '),(17,'6',40,),(17,'6',39,)' at line 1 query: INSERT INTO relatedcontent (nid, vid, include_nid, ordinal_number) VALUES (17,'6',38,),(17,'6',40,),(17,'6',39,) in ......\includes\database.mysqli.inc on line 128.

peter-boeren’s picture

Peter, It is not your mysql version. The values expect 4 columns to fill but only three real values are given. There is a ',' for the the fourth value (ordinal number == weights/position) but it is not filled. I believe that this indeed would trigger an error message in mysql.

peter panes’s picture

Yep thanks i see that now, so I'm assuming its not filling the array correctly, could this be an incompatibility with another module?

I think ill start with a fresh installation and keep adding modules until it stops working.

peter-boeren’s picture

No it is relatedcontent specific.

peter panes’s picture

I'm totally stuck on this, it works on all my other sites but not the one i want to put it on. this is the site i want to use it on www.ccn.ac.uk.

Anyone got any ideas why it doesn't work on this site?

ian-g’s picture

Hi Peter and Peter,

Is this related to my changes? If so I guess its up to me to sort it... I'll have a look and see what I can find.

cheers,

Ian.

ian-g’s picture

Hi again,

Off the top of my head, the function that might be the cause is this function:

/**
 * Insert nid of included nodes into database.
 * Edited by ian-g to supply an array of custom orderings via drag n drop
 * If $newOrderings is null, the old default behaviour is done
 */
function _relatedcontent_db_insert($nid, $vid, $nodes, $newOrderings = NULL) {

  foreach ($nodes as $include_nid => $ordinal) {
    if ($newOrderings == NULL)
    {
      $values[] = array($nid, $vid, $include_nid, $ordinal);		
    }
    else
    {
      // get the new ordinal number from our array
      $ordinal = $newOrderings[$include_nid];
      $values[] = array($nid, $vid, $include_nid, $ordinal);
    }
  }

  if ($values) {
    _relatedcontent_db_query(__FUNCTION__, $values);
  }
}

if somehow my $newOrderings array isn't getting the correct data, then the array of 4 values is missing the 4th value. Peter (Panes) - can you add in some debug info, such as dpr($newOrderings); if the devel module is enabled, or just use print_r($newOrderings); otherwise. Perhaps also show the $values array too after the if/else block, and see what data is being passed in to the function.

It might be that $newOrderings is not null, but is empty, and so the process flow goes into my else block, and its setting the 4th parameter as non-existant.

Why this might be, I'm not sure... But its a possibility.

I'm pleased it works on your other sites though :)

cheers,

Ian.

dooug’s picture

Status: Active » Needs work
FileSize
8.51 KB

Hey all,

I also need table drag support for the related content module. I tested ian-g's posted tarball of the module and was getting the same errors reported by peter-panes in comment #10.

I investigated and found that ian-g's code would only work if the view that populates the Overview table is has $vid = 1 (the view id) in the _relatedcontent_form_submit function.

I fixed the code and it is working as expected. However, while I was debugging, I noticed the code should probably be reworked to adhere to the Drupal coding standards. (Kudos to the original developers/maintainers for the excellent code documentation in this module.) I'd also like to see the feature to drag and order each View group on the Overview table. Additionally, the nodes can be dragged to a view group that they are not a part of, and when updated this is ignored. That could be improved to prevent confusion.

I'll continue to try to improve this feature as I find the time. Until then, here is the latest working patch. Please test and review it.

CodigoVision’s picture

Great patch thanks. The table looked a little strange at first as the handle and the check box are in the same column, the check box was overlapping the title column. here is my quick css fix in case anyone has the same problem.

#relatedcontent-table td .form-item {
  white-space: normal;
  display: inline;
}

Also it would be great if grouping by view was optional so it could be turned off and have full ability to order the content.

www.codigovision.com