summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Davis2012-10-24 13:01:13 (GMT)
committer Ben Davis2012-10-24 13:01:13 (GMT)
commit44f35e32303a78c710b4a5684d18917f2077e518 (patch)
tree85f710af3ee61a1e04ef36dace5848118c4fc83a
parentd97a30895e298da019973130800c7aa19a6632fe (diff)
Issue #1807690 by 10oclock: Add option to keep translation weights synced.
-rw-r--r--weight.install21
-rw-r--r--weight.module36
2 files changed, 56 insertions, 1 deletions
diff --git a/weight.install b/weight.install
index c4315b8..c9d0f24 100644
--- a/weight.install
+++ b/weight.install
@@ -60,6 +60,13 @@ function weight_schema() {
'not null' => TRUE,
'default' => 0,
),
+ 'sync_translations' => array(
+ 'type' => 'int',
+ 'size' => 'tiny',
+ 'unsigned' => FALSE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
),
'primary key' => array('id'),
'foreign keys' => array(
@@ -322,6 +329,20 @@ function weight_update_7208() {
}
/**
+ * Add sync_translations column to weight_settings.
+ */
+function weight_update_7209() {
+ $spec = array(
+ 'type' => 'int',
+ 'size' => 'tiny',
+ 'unsigned' => FALSE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ );
+ db_add_field('weight_settings', 'sync_translations', $spec);
+}
+
+/**
* Decode weight from sticky column.
*/
function _weight_update_7202_decode($sticky) {
diff --git a/weight.module b/weight.module
index a814103..700757a 100644
--- a/weight.module
+++ b/weight.module
@@ -240,6 +240,14 @@ function weight_form_node_type_form_alter(&$form, &$form_state) {
'#default_value' => isset($settings['default']) ? $settings['default'] : 0,
);
+ $form['weight_settings']['sync_translations'] = array(
+ '#type' => 'radios',
+ '#title' => t('Sync translations'),
+ '#description' => t('When changing the weight of a node, also update it\'s translations.'),
+ '#options' => array(t('No'), t('Yes')),
+ '#default_value' => isset($settings['sync_translations']) ? $settings['sync_translations'] : 0,
+ );
+
$form['additional_settings']['#attached']['js'][] = drupal_get_path('module', 'weight') . '/weight.js';
$form['#submit'][] = 'weight_node_type_form_submit';
}
@@ -260,6 +268,7 @@ function weight_node_type_form_submit($form, &$form_state) {
'weight_range' => $values['weight_range'],
'menu_weight' => $values['weight_menu'],
'weight_default' => $values['weight_default'],
+ 'sync_translations' => $values['sync_translations'],
))
->condition('type', $values['type'])
->execute();
@@ -272,6 +281,7 @@ function weight_node_type_form_submit($form, &$form_state) {
'weight_range' => $values['weight_range'],
'menu_weight' => $values['weight_menu'],
'weight_default' => $values['weight_default'],
+ 'sync_translations' => $values['sync_translations'],
))
->execute();
}
@@ -417,6 +427,13 @@ function weight_apachesolr_query_prepare($query) {
* Set the weight of a node.
*/
function _weight_set_weight($node) {
+ if (module_exists('translation') && $node->nid != $node->tnid) {
+ $settings = _weight_get_settings($node->type);
+ if ($settings['sync_translations']) {
+ $node->weight_weight = _weight_get_weight($node->tnid);
+ }
+ }
+
db_merge('weight_weights')
->key(array('entity_id' => $node->nid))
->fields(array(
@@ -434,8 +451,23 @@ function _weight_set_weight($node) {
* 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 ($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' => $node->nid, ':type' => 'node'))->fetchField();
+ array(':id' => $nid, ':type' => 'node'))->fetchField();
return $weight;
}
@@ -455,6 +487,7 @@ function _weight_get_settings($type = NULL) {
'range' => $row->weight_range,
'menu_weight' => $row->menu_weight,
'default' => $row->weight_default,
+ 'sync_translations' => $row->sync_translations,
);
}
}
@@ -466,6 +499,7 @@ function _weight_get_settings($type = NULL) {
'range' => $row->weight_range,
'menu_weight' => $row->menu_weight,
'default' => $row->weight_default,
+ 'sync_translations' => $row->sync_translations,
);
}
}