Hi

I get this error in the error log whenever I start a new survey instance for data entry:

Notice: Undefined property: stdClass::$body in locale_field_entity_form_submit() (line 443 of /home4/[site]/public_html/modules/locale/locale.module).

This is happening because because limeSurvey_sync doesn't create a record in field_data_body/field_revision_body until it tries to fetch the survey results during the sync step. (I verified that, after I start a survey instance, there is a node record but no matching field_data_body record in the db).

This error happens because I have the Locale module (and i18n internationalization / content translation modules) enabled. Those modules are expecting a node to have a Body field and this is a common error seen when nodes are created programatically.

Can you add a Body field to the node when you create it so this error doesn't happen?

Thanks

Comments

thedut’s picture

Hi hanksterr7,

In order to help me to fix this issue, I need a better understanding how to reproduce it.
I guess it occures when a new answer node is created (and not when when a new survey node si created) : could you confirm it ?
Does your survey use token invitations (go to the survey node view page and tell me if "The token table has been created" is checked) ?

hanksterr7’s picture

Yes, happens when a new answer node is created.

For my survey, I have green checkmarks next to these items (seen on the Survey Properties page for my Survey node instance):
--Enable token-based response persistence is set to Yes
--Allow editing answers after completion is set to Yes
--The token table has been created

thedut’s picture

Thanks to your informations, fixing this issue may be quite simple, but I have not enought time right now to test it.
I think the solution may be to edit the ls_anw/ls_answ.module file, Line 571 (dev version) : The ls_answ_prepare() function,
adding at the end of the function something like :

if (module_exists('locale')) {
  if (empty($node->body)) {
    $node->body[LANGUAGE_NONE][0]['value'] = '';
  }
}

You can try it and tell me.

hanksterr7’s picture

Yes, I believe all you need to do is set the body to an empty string when the node is created. I'll try your fix and let you know if that solves the problem. Thanks!

hanksterr7’s picture

Hi

I updated ls_answ_prepare(), adding

$node->body['en'][0]['value'] = 'def';
$node->body['en'][0]['summary'] = 'abc';
$node->body['en'][0]['format'] = 3;

but the field_node_body record is not getting created.

I was able to get it created if I added node_save() to the end of the function (but that obviously not the right thing to do since now the node gets created before the user clicks Save on the node/add/[surveyName] page)

I also tried
$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->body->set(array('value' => 'abc', 'format' => 'full_html'));
but the result was the same

Help?

thedut’s picture

Ok, I don't know why it fails. Anyway, the Locale module is not involve here.
Try this instead :
Forget about my previous code,
Edit the ls_answ/ls_answ.inc file on line 483, the ls_answ_sync_node() function :

        if ($import) {
          // (...) Keep the current code here.
        }
        // New code here :
        else {
          if (empty($node->body)) {
            $node->body[LANGUAGE_NONE][0]['value'] = '';
            $node->body[LANGUAGE_NONE][0]['summary'] = '';
            $node->body[LANGUAGE_NONE][0]['safe_value'] = '';
            $node->body[LANGUAGE_NONE][0]['safe_summary'] = '';
          }
        }

and tell me.

hanksterr7’s picture

sorry, nothing happens when I add that code to ls_answ_sync_node().

I put a watchdog in ls_answ_sync_node() right at the top of the function and the function is not getting called when I click Save from the node/add/[surveyname] page upon starting data entry into a survey. The answer node is getting created when I click Save, and that's the when the stdClass::body error is generated.

hanksterr7’s picture

Ok, I have some more useful info for you.

The error (Undefined property: stdClass::$body in locale_field_entity_form_submit() (line 443 of /home4/[site]/public_html/modules/locale/locale.module) is preventing creation of the field_data_body and field_revision_body records (the error stops execution of a portion of the node creation process initiated by clicking Save on the node/add/[surveyName] form.

I modified locale.module to detect the error and continue on instead of throwing an exception. Once I do this, the field_data_body and field_revision_body records get created when clicking Save.


function locale_field_entity_form_submit($entity_type, $form, &$form_state ) {
  if (field_has_translation_handler($entity_type, 'locale')) {
    $entity = (object) $form_state['values'];
    $current_language = entity_language($entity_type, $entity);
    list(, , $bundle) = entity_extract_ids($entity_type, $entity);

    foreach (field_info_instances($entity_type, $bundle) as $instance) {
      $field_name = $instance['field_name'];
      $field = field_info_field($field_name);
      $previous_language = $form[$field_name]['#language'];

      // Handle a possible language change: new language values are inserted,
      // previous ones are deleted.
watchdog('ls_answ', $entity_type . ' ' . $current_language . ' ' . $previous_language . ' ' . $field_name, null, WATCHDOG_NOTICE, null);
      if ($field['translatable'] && $previous_language != $current_language) {
watchdog('ls_answ', 'doing it', null, WATCHDOG_NOTICE, null);
        if (empty($entity->{$field_name}[$previous_language]))
watchdog('ls_answ', 'empty', null, WATCHDOG_NOTICE, null);
else {
        $form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];
        $form_state['values'][$field_name][$previous_language] = array();
}
      }
    }
  }
}

The first watchdog reports "node en und body", meaning the current language for the node is english and the previous is LANGUAGE_NONE (which is what you are setting as the language of new answer nodes). Since body has a translation handler, the code attempts to execute the
$form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];
line which is the one throwing the exception since $entity->{$field_name}[$previous_language] is not set.

I think all of these errors would go away if you don't arbitrarily use LANGUAGE_NONE as the language of the nodes you are creating, and instead use the site's default language. If $current_language and $previous_language were the same, flow would never pass to the
$form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];
line

Or else, find a way for $entity->{$field_name}[$previous_language]; to be set by the time control gets to this handler

thedut’s picture

Assigned: Unassigned » thedut
Priority: Normal » Minor
Status: Active » Closed (cannot reproduce)

I have dug on this issue.
This issue occurs because, in you case, the $field['translatable'] for the body field is set to TRUE.
But the $field['translatable'] value should be set to FALSE instead. The body datas for multilinguages are stored into distincts nodes, each one having LANGUAGE_NONE body value.
I don't know how you succeed in setting the $field['translatable'] for the body field to TRUE.
I tried to enable the locale module, then the content translation module, and setting various Multilingual support options ('enabled', and 'enabled : with translations') but the $field['translatable'] was always set to FALSE and I couldn't reproduce your issue.
I close this issue as 'cannot reproduce'. Feel free to re-open it if you have new informations.