Two fields are not cloned properly. May be this module was not minded for clonning location info (in this case we can consider this report as a feature request) but, some of the location fields are cloned properly, then, we can consider this a bug report. Nevertheless, the fields can be corrected manually after the clone and the values fixed manually.

- Weight field (of weight module) is cloned with -20 value (or maybe -20 is the default in the screen after the clone)
- State/Province names (of location module) is cloned with a blank value. All other fields of the location module are cloned ok.

Comments about the module: It´s great. As per my experience, is very useful entering nodes with the same categories and location info. In this particular case, it makes me to save a lot of time.

Thanks in advance for your attention,
Gustavo

Comments

pwolanin’s picture

please provide more details- which modules are you using that implement these fields?

Some modules may not clone fields properly if they don't properly handle a node_save() operation on a fully-built node object.

pwolanin’s picture

oops- now I see it's the weight and location modules.

pwolanin’s picture

Ok, this isn't really something I can do anything about for the location module, at least. The problem (I think) is that the data is presented in the node edit form differently than it's finally saved in the node object. So, when a node object is directly submitted, there's a bug. I think the relevant code is highlighted below.

If I someone is highly motivated, they could re-write this clone module for 5.x to generate the appropriate node form and then submit the form- this might bypass this (and similar) problems.

/**
 * Implementation of hook_nodeapi().
 */
function location_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if (!variable_get('location_'. $node->type, 0)) {
    return;
  } 

  switch ($op) {
    case 'validate':
       ...
 //- not relevant for this issue
      ...
      break;
      
    case 'insert':
    case 'update':
      $node->location = location_form2api($node->location);
      
      if (user_access('submit latitude/longitude')) {

see above in hook_node_api where the location is processed through the location_form2api function. This function is below, and I think what's happening is that the call to substr is chopping off the information when only the 2-letter code is present in that field:

/**
 * @param $location
 *   An associative array that has been submitted by an HTML form generated by location_form().
 *
 * @return
 *   An associative array in which the submitted values are modified to pass to the location API
 *   as the $location parameter (excepting location_form()).
 *
 *   This means changing the province field to remove the country code and dash.
 *   For example: California is served by the key 'us-CA' in the location form and this is what is passed when it is
 *                submitted through a form generated by location_form().
 *
 *                This is changed to 'CA' in the returned array.
 */
function location_form2api($location = array()) {
  // The user may have selected a state/province, but did not specify a country
  if (isset($location['province']) && strlen($location['province']) && $location['province'] != 'xx') {
    if (!isset($location['country']) || (isset($location['country']) && !strlen($location['country']))) {
      $location['country'] = substr($location['province'], 0, 2);
    }
  }

  $translated = array();
  $location = is_array($location) ? $location : array();
  foreach ($location as $key => $value) {
    $value = trim($value);
    if ($key == 'province') {
      if (strlen($value) && $value != 'xx') {
        // chop off the 2-letter code and the '-' from the front of the value
        $value = substr($value, 3);
      }
    }
    $translated[$key] = $value;
  }
  return $translated;
}
pwolanin’s picture

Status: Active » Postponed

I took a quick look at the weight module's code. The weight module saves it's data in the node's "sticky" column through some tricks.

So, I think what the problem could be is that the "weight" is stuffed into the sticky field using the "submit" op of hook_nodeapi, which is never called if we go straight to node_save(). So, I don't really think this is fixable in 4.7 (at least on my end). Again, I think the only possible way to fix this would be in 5.x to build a node form and execute it so all the hooks get called.

pwolanin’s picture

Status: Postponed » Active

You might try this alternate version of the module I just posted: http://drupal.org/node/110294

pwolanin’s picture

Status: Active » Closed (fixed)
timtyler’s picture

Version: 4.7.x-1.x-dev » 5.x-2.0

It still is not possible to successfully clone nodes with location-module info.
It is not clear to me why this bug has been closed.

timtyler’s picture

I see different behaviour from the OP. A cloned location is created OK,
with the fields filled in, and it is submitted OK.
But the node it was cloned from is now missing all its location details.
The same behaviour arises with the 1.0 and 2.0 versions of the clone module.

timtyler’s picture

Status: Closed (fixed) » Active

ISTM that what I am seeing is a eid/lid problem.

The cloned form contains:

ISTM that that's going to change the old location and associate it with the new node
(removing its association with the old node in the process).

The only puzzle is how it ever worked at all - /surely/ other people would have
noticed this problem.

Reactivating - in case someone can help.

timtyler’s picture

I forgot to 'quote' the code - sorry:

The cloned form contains:

<input type="hidden" name="locations[0][lid]" id="edit-locations-0-lid" value="41"  />
timtyler’s picture

I've raised an issue with the location module:

http://drupal.org/node/188175

One possible fix works from that end.

pwolanin’s picture

I closed the this issue at one point because the bug seems to lie with the module creating the node type and is not something that can be fixed readily by the clone module (which is a pretty minimal piece of code).

pwolanin’s picture

Status: Active » Closed (fixed)

closing again.

csc4’s picture

Status: Closed (fixed) » Active

Sorry pwolanin - opening again as I think this properly belongs here rather than in the location thread.

I've made some progress on this, though it's not the definitive answer I thought I'd share what I'd got.

ISTM the problem stems from location deleting the location before reentering it - and the location array contains the eid (which is the link to the node revision - not nid) of the node you're cloning, thus the location is lost. The other problem is location_form2api attempts to change provinces from CC-province to province so provinces need 'paddiing'

I know there's big work on location at the moment but I need this now and figure it might help someone else too. So I've gone with a fix to node_clone as probably making most sense in the short term...

I'm experimenting with

      drupal_set_title(check_plain($node->title));

      if (module_exists(location)) { 
         if (!empty($node->locations[0])) {
           $node->locations[0]['eid'] = $node->vid;
           if (!empty($node->locations[0]['province'])) { 
           //need to pad the province to stop function location_form2api chopping real data
             $node->locations[0]['province'] = 'aa-' . $node->locations[0]['province'];
           }         
         }      
      }
      

      if (variable_get('clone_reset_'. $node->type, FALSE)) {

in function clone_node in clone.module around line 172 and it seems to be working for me - I realise this is hard coded for only one location ATM - I only use one location and it's experimental code.

It seems to be working for me so far, but as it's a workaround (as location is hopefully changing with all bdragon's work) I'm not sure it's worth generalising it to many locations and then submitting it as a node_clone patch.

Leeteq’s picture

Subscribing.

pwolanin’s picture

the 5.x versions now have an extra hook so you can add on a module that does cleanup like this as needed.

vegasphotog’s picture

Any clear resolution here? I have the location module as part of a "meeting" content. I want to have the address clone with the meeting. I am in 5.7. Is there a workaround now?

richygecko’s picture

Has anyone come up with a working solution to this issue?

pwolanin’s picture

Status: Active » Closed (won't fix)