I'm trying to make a check that the user has not selected two contradictory checkboxes. The following code makes the change OK during the change of a node, but not during the creation. In both new and update, the conditions are met and it enters the unset() part of the code. But only during the update does it actually work. Ideas how to fix? Thanks!

* Implements hook_node_presave().
function lingopolo_node_presave($node) {
// Ensure that phrases do not appear in the "Level" lesson
if ($node->type == 'thai_word'
&& isset($node->field_difficulty_level['und'][0]['tid'])
  && isset(
$node->field_recording_type['und'][0]['tid'])) {
$level = $node->field_difficulty_level['und'][0]['tid'];
$recording_type = $node->field_recording_type['und'][0]['tid'];
    if (
drupal_set_message("Removing from the Level lesson, since Recording Type is Phrases or Dialogues.");


Because you didn't pass it with reference.

/ function lingopolo_node_presave($node) {

/ function lingopolo_node_presave(&$node) {

// Ayesh

Hi Ayesh,

Thank you for your suggestion. I tried it and it didn't work.

I see that the documentation does not require this
but I thought that I'd try anyway.

The reason seems to appear here:

With PHP 5, objects passed as arguments for a function are passed by reference. The example is correct, since Drupal 7 requires PHP 5.

So basically the $node object is being passed by reference anyway.

Maintainer of the Flipcard module visible in use at the website to learn French and learn Thai