I need help with cloning an entry that has matrix fields for photos. Entries are made/edited using Channel Forms. The clone is generated using an extension to the channel_form_submit_entry_end hook
My Method:
public function generate($channel_form_obj)
{
$entry_id = '';
$quote_required = 0;
ee()->security->restore_xid();
//I If the form has errors, don't bother
if (!empty($channel_form_obj->errors) || !empty($channel_form_obj->field_errors))
{
return;
}
// Grab the group ID
$author_group_id = ee()->session->userdata('group_id');
// Forge the group ID - the contractors dont normally have quote authority
ee()->session->userdata['group_id'] = 1;
// Set the roofer's report to lower case before checking for the quote word
$lc_roofer_report = strtolower( $channel_form_obj->entry('roofer_report') );
// Set the order status to lower case before checking for the quote word
$lc_order_status = strtolower( $channel_form_obj->entry('order_status') );
// All repairs requiring further quotes have the word "required" either
// in the roofer's report or the order status. Both entries are made using a slect list
$reactive_category = $channel_form_obj->entry('categories')[0];
if (
preg_match("/\brequired\b/i", $lc_roofer_report) == 1
||
preg_match("/\brequired\b/i", $lc_order_status) ==
)
{
$quote_required = 1;
}
if($reactive_category == 1 && $quote_required == 1)
{
// Grab the data we need for the quote page and set spawning entry ID so we can find its spawn if we have an edit
$data = array(
'title' => $channel_form_obj->entry('title'),
'field_id_50' => $channel_form_obj->entry('entry_id'),
'field_id_3' => $channel_form_obj->entry('customer_id'),
'field_id_37' => $channel_form_obj->entry('customer_reference'),
'field_id_5' => $channel_form_obj->entry('job_address'),
'field_id_40' => $channel_form_obj->entry('town'),
'field_id_30' => $channel_form_obj->entry('postcode'),
'field_id_27' => $channel_form_obj->entry('roof_type'),
'field_id_28' => $channel_form_obj->entry('roof_condition'),
'field_id_32' => $channel_form_obj->entry('job_photos'), // This causes the problem
'field_id_33' => $channel_form_obj->entry('quote_details'),
'field_id_34' => $channel_form_obj->entry('materials_and_plant'),
'field_id_46' => $channel_form_obj->entry('access'),
'field_id_41' => $channel_form_obj->entry('notepad'),
'author_id' => $channel_form_obj->entry('author_id'),
'category' => array(2),
'field_id_20' => 'Pending'
);
// Set the entry_id to zero in case this is an entry or an edit not previously spawned,
// otherwise ve heff crepp
$data['entry_id'] = 0;
$entry_id = 0;
// If this is an edit, check if it is a re-edit of a previous spawn so we can correct
// the spawned quote
if($channel_form_obj->edit == 1)
{
$spawning_entry_id = $channel_form_obj->entry('entry_id');
ee()->db->select();
ee()->db->from('exp_channel_data');
ee()->db->where('exp_channel_data.field_id_50', $spawning_entry_id);
$query = ee()->db->get();
if ($query->num_rows() > 1)
{
// Throw error message - too many spawns
return;
}
elseif ($query->num_rows() == 1)
{
// We have a re-edit of a prevously spawned quote
$row = $query->row_array();
$entry_id = $row['entry_id'];
//echo 'Entry ID '.$entry_id.'
This code generates the following warning:
';
}
}
$group_id = $this->EE->session->userdata('group_id');
if (ee()->session->userdata('group_id') != '1')
{
//Error Can't Post
';
}
else
{
// OK can post
$channel_id = $channel_form_obj->entry('channel_id');
ee()->load->library('api');
ee()->api->instantiate('channel_entries');
ee()->api_channel_entries->save_entry($data, $channel_id, $entry_id, $autosave=false);
}
}
return;
}
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'is_draft'
Filename: matrix/ft.matrix.php
Line Number: 2373
And the matrix field entries are not cloned.
I obviously do not know how to clone the matrix fields in this situation.
EE is V2.7.3 and matrix V2.5.10
Can anyone point me at how to clone the the matrix fields?