Closed laryn closed 4 years ago
More:
Notice: Undefined property: Node::$language in paragraphs_clone_node_alter() (line 14 of /path/modules/paragraphs/paragraphs.node_clone.inc).
Notice: Undefined variable: entity_wrapper in paragraphs_clone_items() (line 59 of /path/modules/paragraphs/paragraphs.node_clone.inc).
Notice: Trying to get property of non-object in paragraphs_clone_items() (line 59 of /path/modules/paragraphs/paragraphs.node_clone.inc).
Error: Call to a member function value() on null in paragraphs_clone_items() (line 59 of /path/modules/paragraphs/paragraphs.node_clone.inc).
Line 59:
$old_items = $entity_wrapper->{$field_name}->value();
Line 14:
$language = $node->language;
Line 14 of course should be $node->langcode
Line 59 is a bigger issue. This code block:
$field_items = field_get_items($entity_type, $entity, $field_name);
if ($field_items) {
$reset_item = reset($field_items);
$old_items = $reset_item['value'];
}
// $entity_wrapper = entity_metadata_wrapper($entity_type, $entity);
$old_items = $entity_wrapper->{$field_name}->value();
if (!is_array($old_items)) {
$old_items = array($old_items);
}
should really be
$field_items = field_get_items($entity_type, $entity, $field_name);
$old_items = NULL;
if ($field_items) {
$reset_item = reset($field_items);
$old_items = $reset_item['value'];
}
if (!is_array($old_items)) {
$old_items = array($old_items);
}
But that will only work for fields that have a 'value'
key, not for things like files ('fid'
) etc, but maybe commit it like that to get it working for most fields at least, then create an issue to expand the $old_items = $reset_item['value'];
to a broader
if (isset($reset_item['value'])) { ...
elseif (isset($reset_item['fid'])) { ...
etc
It would be nice if Node Clone could work with Paragraphs (and it looks like the functionality should be there, just needs some tweaks apparently).