1

I am storing an array as a JSON encoded serialized data field in Drupal 7 using the Serialized Field module.

If I have an array of 20 elements and try to overwrite it with an array of 10 elements, I would expect to only have 10 elements in the field. But instead I am getting the 10 elements (keys 0-9) from my new array AND THEN the higher keyed elements from the old array (10-19).

Is there a way to empty out the old previously stored array values before writing the new array values?

I have tried the following but nothing completely overwrites the field:

$node->field_test[LANGUAGE_NONE][0]['value'] = "";

$node->field_test[LANGUAGE_NONE][0]['value'] = NULL;

$node->field_test[LANGUAGE_NONE][0]['value'] = array();

$node->field_test[LANGUAGE_NONE][0]['value'] = array(NULL);

$node->field_test = array(NULL);

$node->field_test = NULL;

0

A colleague suggested a solution that worked.

The Field Settings has a group of settings called "Serialization Options" which includes a checkbox option for "Namespace the data". In my initial configuration that box was checked. I unchecked the box and saved the field settings and my problem was solved.

Final solution: Uncheck "Namespace the data" in the Field Settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.