I have been trying to debug a problem with translated taxonomies and content_taxonomy and have traced the problem down to the following line in content.module (_content_widget_invoke, c. line 624):
$node_field = array_merge($node_field, content_default_value($node, $field, $node_field));
This use of array_merge has a side-effect of renumbering the array. For example, prior to performing the array_merge the node_field object looks like this:
pre array_merge: Array
(
[91] => Array
(
[95] => stdClass Object
(
[tid] => 95
[vid] => 7
[name] => English Child B
[description] =>
[weight] => 0
[language] => en
[trid] => 13
)
)
)
After the merge we get:
post node_field: Array
(
[0] => Array
(
[95] => stdClass Object
(
[tid] => 95
[vid] => 7
[name] => English Child B
[description] =>
[weight] => 0
[language] => en
[trid] => 13
)
)
[tids] => Array
(
[0] => 0
)
)
Notice that the '91' index has been renumbered to 0.
This causes problems in content_taxonomy_options.module's hook_widget which is as follows:
function content_taxonomy_options_widget($op, &$node, $field, &$node_field) {
$vid = $field['vid'];
$tid = $field['tid'];
$depth = (!empty($field['depth'])) ? $field['depth'] : NULL;
//default values
$default_values = array();
if(is_array($node_field[$field['tid']])) {
$default_values = array_keys($node_field[$field['tid']]);
}
else {
if (is_array($field['widget']['default_value']['tids'])) {
$default_values = $field['widget']['default_value']['tids'];
}
else if (is_array($field['widget']['default_value'])) {
$default_values = array_keys($field['widget']['default_value']);
}
}
Here $field is as follows:
field: Array
(
[field_name] => field_vocab_1
[type] => content_taxonomy
[required] => 0
[multiple] => 0
[db_storage] => 1
[save] => tag
[vid] => 7
[tid] => 91
[depth] =>
[widget] => Array
(
[defa...
So the look up on $node_field[$field['tid']] fails because the $node_field array is not numbered as expected.
If I change the array_merge in content.module to:
$node_field += content_default_value($node, $field, $node_field);
I get:
post node_field: Array
(
[91] => Array
(
[95] => stdClass Object
(
[tid] => 95
[vid] => 7
[name] => English Child B
[description] =>
[weight] => 0
[language] => en
[trid] => 13
)
)
[tids] => Array
(
[0] => 0
)
)
And everything works as expected.
I'm not sure how the CCK module is supposed to work so I'm not sure if this is the correct place to fix it.
This is only a problem when creating new nodes. This is because the array_merge is only executed for new nodes due to the preceding line:
if ($op == 'prepare form values' && empty($node->nid)) {
I think a fix is appropriate because otherwise the format of the array differs when creating a new node and when editing an existing node.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | content.module.patch | 809 bytes | brianskold |
| content.module.patch | 921 bytes | brianskold |
Comments
Comment #1
brianskold commentedSorry, that last patch was broken. This one should be better.
Comment #2
karens commentedThe D5 version is no longer being supported. Sorry.