Created
November 8, 2013 08:16
-
-
Save jussiviitamaki/7367880 to your computer and use it in GitHub Desktop.
Generic diff function to diff node field current and original valeu on presave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _my_module_diff_field_values($node, $field_name) { | |
$array_a = array(); | |
$array_b = array(); | |
if(!empty($node->{$field_name})) { | |
foreach($node->{$field_name}[LANGUAGE_NONE] as $key => $value) { | |
if(isset( $value['nid'])) { | |
$array_a[] = $value['nid']; | |
} | |
// Try value | |
elseif(isset( $value['value'])) { | |
$array_a[] = $value['value']; | |
} | |
} | |
} | |
if(!empty($node->original->{$field_name})) { | |
foreach($node->original->{$field_name}[LANGUAGE_NONE] as $key => $value) { | |
// Try nid | |
if(isset( $value['nid'])) { | |
$array_b[] = $value['nid']; | |
} | |
// Try value | |
elseif(isset( $value['value'])) { | |
$array_b[] = $value['value']; | |
} | |
} | |
} | |
$diff = array_diff($array_a, $array_b); | |
$rev_diff = array_diff($array_b, $array_a); | |
if(!empty($diff)) { | |
return TRUE; | |
} elseif(!empty($rev_diff)) { | |
return TRUE; | |
} else { | |
return FALSE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment