I needed support for the form Synchronize translations (i18n_sync), I made this patch to integrate the synchronization of node weight, works both in the node edit and during the batch update in views.

I check if the i18n_sync module is installed and use his hook

My idea started from the 6.x issue #660052 Weight: sync node translations

Any test is appreciated.

Comments

StatusFileSize
new1.59 KB

Patch

StatusFileSize
new4.14 KB

I taken a slightly different approach to this. When getting or setting the weight of a node, we are now checking to see if it is a translation and if it is set the weight equal to the parent node. I made this optional by adding the option to enable it to the weight settings form so it can be turned on or off per content type. If you could test this patch and let me know if it works for you I'd appreciate it.

Status:Needs review» Fixed

I had some time to test this and committed the patch in #2.

Status:Fixed» Closed (fixed)

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

Status:Closed (fixed)» Needs review

There should be a test missing for the patch in #1807690-2: Synchronize translations support. If $settings is null ($settings['sync_translations']) creates a bootstrap.

There is a test missing confirmed thanks to my Netbeans debugger. If $settings is a null array then there is an error with $settings['sync_translations']. That is why I add a test with if (empty($settings))

The following code doesn't generate anymore error but it shouldn't be optimal. I don't have the required level in Drupal API and php to optimize it. There is possibly a better solution as there is many possibilities that gives the same $nid = $node->nid;.

/**
* Get the weight of a node.
*/
function _weight_get_weight($node) {
  if (is_numeric($node)) {
    $nid = $node;
  }
  elseif (module_exists('translation') && $node->nid != $node->tnid) {
    $settings = _weight_get_settings($node->type);
    if (empty($settings)) {
      $nid = $node->nid;
    }
    else {
      if ($settings['sync_translations']) {
        $nid = $node->tnid;
      }
      else {
        $nid = $node->nid;
      }
    }
  }
  else {
    $nid = $node->nid;
  }
  $weight = db_query("SELECT weight FROM {weight_weights} WHERE entity_id=:id AND entity_type=:type",
    array(':id' => $nid, ':type' => 'node'))->fetchField();
  return $weight;
}

I am unable to reproduce this error. Could you provide a bit more detail on the steps to reproduce it?

Status:Needs review» Active

Don't know exactly. I didn't search for nodes that create the issue.
Perhaps that can come from one of the language disabled or some translated node but not in every language, only some of them.

That happens with when I use ddblock(Dynamic display block) displaying nodes.
Those nodes have weight disabled and translation enabled.

Status:Active» Fixed

I was able to reproduce this and applied the fix from #5.

Status:Fixed» Closed (fixed)

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