summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCzövek András2011-03-14 09:24:53 (GMT)
committerCzövek András2011-03-14 09:24:53 (GMT)
commit201e5fa6b04c0ab2c44b0fa1f71c6f38986d391c (patch)
tree53379e04e015067197f2b096333b6bee3e214fd1
parent776b25f31d1bc4073ac7e8afd9f550d1e57da6f7 (diff)
Issue #1091616 by DamienMcKenna: Changed some coding standard stuff.
-rw-r--r--CHANGELOG.txt6
-rw-r--r--corresponding_node_references.crud.inc91
-rw-r--r--corresponding_node_references.info3
-rw-r--r--corresponding_node_references.module71
4 files changed, 91 insertions, 80 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index fd8d4e6..e3c0554 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,2 +1,6 @@
-Issue #1091616 by czigor: Fix for settings form when there are no corresponding fields.
+Journal 7.x-1.0, 2010-01-07
+---------------------------
+
+Issue #1091616 by DamienMcKenna: Changed some coding standard stuff.
+Issue #1091612 by czigor: Fix for settings form when there are no corresponding fields.
diff --git a/corresponding_node_references.crud.inc b/corresponding_node_references.crud.inc
index fbbd5b0..09b80ea 100644
--- a/corresponding_node_references.crud.inc
+++ b/corresponding_node_references.crud.inc
@@ -1,16 +1,19 @@
<?php
/**
* @file
- * Include file providing corresponding node reference insert, update, and delete handling.
+ * Include file providing corresponding node reference insert, update, and
+ * delete handling.
*/
/**
* Add any corresponding references on node insertion.
*
- * @param $home_node the node object catched in the node api on this node a reference is made to the away node
+ * @param $home_node the node object catched in the node api on this node a
+ * reference is made to the away node.
* @param $home_field the field on the home node used to make the reference
- * @param $away_node_type the type of the away node
- * @param $away_field the name of the field on the away node referencing to the home node
+ * @param $away_node_type the type of the away node.
+ * @param $away_field the name of the field on the away node referencing to
+ * the home node.
*/
function corresponding_node_references_insert($home_node, $home_field, $away_node_type, $away_field) {
$old_node = node_load($home_node->nid, NULL, TRUE);
@@ -21,28 +24,29 @@ function corresponding_node_references_insert($home_node, $home_field, $away_nod
foreach ($fields as $reference) {
if (!empty($reference['nid'])) {
// Load the referenced node if it is of the specified away type.
- //TODO: Do this with EntityFieldQuery
- //See http://api.drupal.org/api/drupal/modules--node--node.module/function/node_load_multiple/7
+ // TODO: Do this with EntityFieldQuery
+ // See http://api.drupal.org/api/drupal/modules--node--node.module/function/node_load_multiple/7
if ($referenced_node = node_load($reference['nid'], NULL, FALSE)) {
if ($referenced_node->type == $away_node_type) {
// Add the new reference.
- // If there are no other references, we need to make sure this is delta 0
+ // If there are no other references, we need to make sure this
+ // is delta 0
if ($referenced_node->{$away_field}[$lang][0]['nid'] == NULL) {
$referenced_node->{$away_field}[$lang][0]['nid'] = $home_node->nid;
}
else {
// Add the new reference.
- //Check for doubles, could happen when nodes of same type are referenced
+ // Check for doubles, could happen when nodes of same type are
+ // referenced.
$exists = FALSE;
foreach ($referenced_node->{$away_field}[$lang] as $key => $value) {
if ($value['nid'] == $home_node->nid) {
$exists = TRUE;
break;
-
}
}
- if (!$exists) {
+ if (!$exists) {
$referenced_node->{$away_field}[$lang][] = array('nid' => $home_node->nid);
}
}
@@ -60,16 +64,19 @@ function corresponding_node_references_insert($home_node, $home_field, $away_nod
*
* Corresponding changes are made for any references removed or added.
*
- * @param $home_node the node object catched in the node api on this node a reference is made to the away node
+ * @param $home_node the node object catched in the node api on this node a
+ * reference is made to the away node.
* @param $home_field the field on the home node used to make the reference
- * @param $away_node_type the type of the away node
- * @param $away_field the name of the field on the away node referencing to the home node
- * @param $process_unchanged whether or not to process node reference fields whose values have not changed.
- * This is useful for nodes that existed before installing this module and have corresponding node
- * reference fields that don't match up.
+ * @param $away_node_type the type of the away node.
+ * @param $away_field the name of the field on the away node referencing to
+ * the home node.
+ * @param $process_unchanged whether or not to process node reference fields
+ * whose values have not changed. This is useful for nodes that
+ * existed before installing this module and have corresponding node
+ * reference fields that don't match up.
*/
function corresponding_node_references_update($home_node, $home_field, $away_node_type, $away_field, $process_unchanged = FALSE) {
- //Since node is not saved yet, $old_node and $home_node are different!
+ // Since node is not saved yet, $old_node and $home_node are different!
$old_node = node_load($home_node->nid, NULL, FALSE);
$old = $new = array();
@@ -85,7 +92,8 @@ function corresponding_node_references_update($home_node, $home_field, $away_nod
}
}
- // If we are processing unchanged references, remove all new references from the old references.
+ // If we are processing unchanged references, remove all new references
+ // from the old references.
if ($process_unchanged) {
foreach ($old as $lang => $data) {
$old[$lang] = array_diff($old[$lang], $new[$lang]);
@@ -111,7 +119,7 @@ function corresponding_node_references_update($home_node, $home_field, $away_nod
foreach ($removed as $nid) {
// Load the referenced node if it is of the specified away type.
if ($referenced_node = node_load($nid, NULL, FALSE)) {
- //Self-references are handled by the node_reference module anyway
+ // Self-references are handled by the node_reference module anyway.
if ($referenced_node->type == $away_node_type && $nid != $home_node->nid) {
if (isset($referenced_node->{$away_field}[$lang]) && is_array($referenced_node->{$away_field}[$lang])) {
// Iterate through the away node's references.
@@ -131,14 +139,14 @@ function corresponding_node_references_update($home_node, $home_field, $away_nod
}
}
// Handle added references.
- // No array diff a reference overload could of happend or a mass update
+ // No array diff a reference overload could of happend or a mass update.
if ($added = $new) {
foreach ($added as $added_lang => $added_langdata) {
foreach ($added_langdata as $nid) {
// Load the referenced node if it is of the specified away type.
if ($referenced_node = node_load($nid, NULL, FALSE)) {
- //Self-references are handled by the node_reference module anyway
+ // Self-references are handled by the node_reference module anyway.
if ($referenced_node->type == $away_node_type && $nid != $home_node->nid) {
// Detect whether the reference already exists.
$exists = FALSE;
@@ -151,8 +159,9 @@ function corresponding_node_references_update($home_node, $home_field, $away_nod
}
}
- //Empty places are removed
- //Yes this means the deltas change on the away node when a reference is made on the home node
+ // Empty places are removed.
+ // Yes this means the deltas change on the away node when a
+ // reference is made on the home node.
$values = array();
if (isset($referenced_node->{$away_field}[$added_lang])) {
foreach ($referenced_node->{$away_field}[$added_lang] as $value) {
@@ -165,7 +174,7 @@ function corresponding_node_references_update($home_node, $home_field, $away_nod
// Add the new reference. Don't create a duplicate.
if (!$exists) {
- //Get the allowed values
+ // Get the allowed values.
$unlimited = FALSE;
$field = field_info_field($away_field);
if ($field) {
@@ -177,7 +186,7 @@ function corresponding_node_references_update($home_node, $home_field, $away_nod
$allowed_references = $field['cardinality'];
}
- //check for reference overloading
+ // Check for reference overloading.
$references = count($referenced_node->{$away_field}[$added_lang]) + 1;
if (($allowed_references >= $references) || $unlimited) {
$referenced_node->{$away_field}[$added_lang][] = array('nid' => $home_node->nid);
@@ -187,17 +196,15 @@ function corresponding_node_references_update($home_node, $home_field, $away_nod
$t_reference = format_plural($references, '1 reference', '@count references');
$t_allowed = format_plural($allowed_references, '1 reference is', '@count references are');
drupal_set_message(
- t('Reference overloading: @title would of had @t_reference and only @t_allowed permitted. Before adding a reference,
- you would need to <a href="@url">edit</a> @title to remove an existing reference and resave this node to have make it correspond.
- Or you could allow this reference instance to have more references, go to the cck field settings of the instance',
- array(
- '@title' => $referenced_node->title,
- '@url' => url('node/' . $referenced_node->nid),
- '@t_reference' => $t_reference,
- '@t_allowed' => $t_allowed,
- )
- ),
- 'error'
+ t('Reference overloading: @title would of had @t_reference and only @t_allowed permitted. Before adding a reference, you would need to <a href="@url">edit</a> @title to remove an existing reference and resave this node to have make it correspond. Or you could allow this reference instance to have more references, go to the cck field settings of the instance',
+ array(
+ '@title' => $referenced_node->title,
+ '@url' => url('node/' . $referenced_node->nid),
+ '@t_reference' => $t_reference,
+ '@t_allowed' => $t_allowed,
+ )
+ ),
+ 'error'
);
}
}
@@ -212,10 +219,12 @@ function corresponding_node_references_update($home_node, $home_field, $away_nod
/**
* Remove corresponding references on node deletion.
*
- * @param $home_node the node object catched in the node api on this node a reference is made to the away node
- * @param $home_field the field on the home node used to make the reference
- * @param $away_node_type the type of the away node
- * @param $away_field the name of the field on the away node referencing to the home node
+ * @param $home_node the node object catched in the node api on this node a
+ * reference is made to the away node.
+ * @param $home_field the field on the home node used to make the reference.
+ * @param $away_node_type the type of the away node.
+ * @param $away_field the name of the field on the away node referencing to
+ * the home node.
*/
function corresponding_node_references_delete($home_node, $home_field, $away_node_type, $away_field) {
// Iterate through the field's references.
@@ -244,7 +253,7 @@ function corresponding_node_references_delete($home_node, $home_field, $away_nod
/**
* Update field data.
*
- * @param $node the referenced node to be updated
+ * @param $node the referenced node to be updated.
*/
function _corresponding_node_references_update(&$node) {
node_save($node);
diff --git a/corresponding_node_references.info b/corresponding_node_references.info
index 57d44cb..915ca3b 100644
--- a/corresponding_node_references.info
+++ b/corresponding_node_references.info
@@ -1,5 +1,4 @@
name = Corresponding Node References
description = Syncs the node reference between two node types which have a nodereference to each other.
core = 7.x
-dependencies[] = node_reference
-
+dependencies[] = node_reference \ No newline at end of file
diff --git a/corresponding_node_references.module b/corresponding_node_references.module
index 7cc070b..63d742a 100644
--- a/corresponding_node_references.module
+++ b/corresponding_node_references.module
@@ -1,7 +1,8 @@
<?php
/**
* @file
- * Module file providing the "corresponding node reference" module main functions.
+ * Module file providing the "corresponding node reference" module main
+ * functions.
*/
/**
@@ -31,7 +32,6 @@ function corresponding_node_references_menu() {
'page arguments' => array('corresponding_node_references_update_form'),
'access arguments' => array('administer corresponding node references settings'),
'type' => MENU_LOCAL_TASK,
-
);
return $items;
@@ -41,26 +41,26 @@ function corresponding_node_references_menu() {
* Implements hook_permission().
*/
function corresponding_node_references_permission() {
- return array('administer corresponding node references settings' => array(
- 'title' => t('Administer corresponding node reference settings'),
- 'description' => t('Administer corresponding node reference settings'),
- ));
+ return array(
+ 'administer corresponding node references settings' => array(
+ 'title' => t('Administer corresponding node reference settings'),
+ 'description' => t('Administer corresponding node reference settings'),
+ )
+ );
}
/**
- * The settings form
+ * The settings form.
*/
function corresponding_node_references_settings_form() {
- $form['intro'] = array('#markup' => t('Check which node references should listen to each other.
- When checking a check box a reference on node type A to node B will automatically update the node reference field on node B
- adding an entrie which points to node A.'));
+ $form['intro'] = array('#markup' => t('Check which node references should listen to each other. When checking a check box a reference on node type A to node B will automatically update the node reference field on node B adding an entrie which points to node A.'));
$result = db_query("SELECT field_name, data FROM {field_config} WHERE type = :type", array(':type' => 'node_reference'));
foreach ($result as $row) {
$data = unserialize($row->data);
- foreach ($data['settings']['referenceable_types'] as $reference) {
- if ($reference != '0') {
- $references[$row->field_name][] = $reference;
+ foreach ($data['settings']['referenceable_types'] as $reference) {
+ if ($reference != '0') {
+ $references[$row->field_name][] = $reference;
}
}
}
@@ -70,8 +70,9 @@ function corresponding_node_references_settings_form() {
foreach ($result as $row) {
if (!empty($references[$row->field_name])) {
foreach ($references[$row->field_name] as $reference) {
- if ($row->entity_type == 'node')
- $fields_to_compare[] = array('field_type' => $row->field_name, 'bundle' => $row->bundle, 'reference' => $reference);
+ if ($row->entity_type == 'node') {
+ $fields_to_compare[] = array('field_type' => $row->field_name, 'bundle' => $row->bundle, 'reference' => $reference);
+ }
}
}
}
@@ -122,7 +123,7 @@ function corresponding_node_references_settings_form() {
}
/**
- * Submit function for settings form
+ * Submit function for settings form.
*/
function corresponding_node_references_settings_form_submit($form, $form_values) {
db_update('corresponding_node_references')->fields(array('enabled' => 0))->execute();
@@ -145,7 +146,7 @@ function corresponding_node_references_settings_form_submit($form, $form_values)
}
/**
- * Formats a label
+ * Formats a label.
*/
function corresponding_node_references_format_label($key) {
$key = explode(' ', $key);
@@ -174,13 +175,13 @@ function corresponding_node_references_node_delete($node) {
corresponding_node_references_processing_node('delete', $node);
}
-
/**
* Process a node's corresponding node references.
*
* @param $op the operation being performed on the node.
* @param $node the node object
- * @param $process_unchanged whether or not to process node reference fields whose values have not changed.
+ * @param $process_unchanged whether or not to process node reference fields
+ * whose values have not changed.
*/
function corresponding_node_references_processing_node($op, $node, $process_unchanged = FALSE) {
module_load_include('inc', 'corresponding_node_references', 'corresponding_node_references.crud');
@@ -197,6 +198,7 @@ function corresponding_node_references_processing_node($op, $node, $process_unch
if ($key[0] != $key[2]) {
break;
}
+
// Fall through.
case $key[2]:
$args = array($node, $key[3], $key[0], $key[1], $process_unchanged);
@@ -215,12 +217,13 @@ function corresponding_node_references_update_form() {
$form = array();
$form['intro'] = array(
- '#value' => t('This will update all the existing nodes for the selected content types so that their node reference fields are in sync.') . '<br />' . t('This process may take a long time depending on the number of nodes you are updating.') . '<br />' . t('When the process is finished you will see a count of the number of nodes that were updated.'));
+ '#value' => t('This will update all the existing nodes for the selected content types so that their node reference fields are in sync.') . '<br />' . t('This process may take a long time depending on the number of nodes you are updating.') . '<br />' . t('When the process is finished you will see a count of the number of nodes that were updated.')
+ );
- $options = _node_types_build()->types;
- foreach ($options as $type => $class) {
- $options[$type] = $class->name;
- }
+ $options = _node_types_build()->types;
+ foreach ($options as $type => $class) {
+ $options[$type] = $class->name;
+ }
$form['types'] = array(
'#type' => 'checkboxes',
@@ -229,8 +232,6 @@ function corresponding_node_references_update_form() {
'#description' => t('Select the node types that you want to update.'),
);
-
-
$form['limit'] = array(
'#type' => 'select',
'#title' => t('Number of nodes to process at once'),
@@ -290,7 +291,10 @@ function corresponding_node_references_update_form_submit($form, &$form_state) {
function corresponding_node_references_batch_index_remaining($types, $limit) {
$batch = array(
'operations' => array(
- array('corresponding_node_references_batch_update_existing_nodes', array($types, $limit)),
+ array(
+ 'corresponding_node_references_batch_update_existing_nodes',
+ array($types, $limit)
+ ),
),
'finished' => 'corresponding_node_references_batch_update_existing_finished',
'title' => t('Processing'),
@@ -318,11 +322,7 @@ function corresponding_node_references_batch_update_existing_nodes($types, $limi
$args = $types;
$args[] = $context['sandbox']['current_node'];
// Get node IDs to update.
- $result = db_query_range("SELECT nid
- FROM {node}
- WHERE type IN (:types)
- AND nid > :args
- ORDER BY nid", 0, $limit, array(':types' => $types, ':args' => $args[0]));
+ $result = db_query_range("SELECT nid FROM {node} WHERE type IN (:types) AND nid > :args ORDER BY nid", 0, $limit, array(':types' => $types, ':args' => $args[0]));
while ($row = $result->fetchObject()) {
$node = node_load($row->nid);
@@ -339,8 +339,8 @@ function corresponding_node_references_batch_update_existing_nodes($types, $limi
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
- // Put the total into the results section when we're finished so we can
- // show it to the admin.
+ // Put the total into the results section when we're finished so we can show
+ // it to the admin.
if ($context['finished']) {
$context['results']['count'] = $context['sandbox']['progress'];
}
@@ -364,5 +364,4 @@ function corresponding_node_references_batch_update_existing_finished($success,
$message = 'An error occurred while processing ' . $error_operation[0] . ' with arguments:' . print_r($error_operation[0], TRUE);
}
drupal_set_message($message, $type);
-}
-
+} \ No newline at end of file