Closed (fixed)
Project:
Matrix field
Version:
5.x-1.2
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
30 Jul 2008 at 00:19 UTC
Updated:
20 Feb 2009 at 19:40 UTC
I was writing an application that took advantage of the matrix field and (for other reasons) had to call $node = node_load($nid) on a node with a matrix field and then it later called node_save($node) on that same node. When this happened, the contents of the matrix field were removed. This is what I was doing to see the problem:
$node = node_load($nid);
dpr($node->field_matrix_field_field);
node_save($node);
$node = node_load($nid, NULL, TRUE); // to not load the node from cache
dpr($node->field_matrix_field_field);
I tracked the problem down and what I think is happening is the node_load is returning an array of matrix field rows for $node->field_matrix_field_field, but node save is expecting an array called 'matrix' that contains the array of matrix field rows. I was able to do a workaround like this, but assume there is a better solution:
$node = node_load($nid);
$node->field_matrix_field = array('matrix' => $node->field_matrix_field);
... some other stuff ...
node_save($node);
Comments
Comment #1
Joshua Brunner commentedUhm, same problem heere.
Line 77 in matrix.module:
$additions = array($field['field_name'] => $values);Should be:
$additions[$field['field_name']]['matrix'] = $values;Never change a running system. If You change this line or add my one below the Original one, you have to fix your contemplates :(.
This Code should work without any changes at the matrix.module:
Joshua
Comment #2
aaron1234nz commentedThanks Joshua,
I'll take a look
Comment #3
aaron1234nz commentedanother patch I committed has fixed this issue (5.x and 6.x branch)