I’m using the hook before_channel_entry_delete to get custom fields of the deleted entry and use that in another context. But, when I add the hook method and try to get data, all the the custom field values are empty. For example, the hook method I’m using:
public function hook_before_channel_entry_delete($entry, $values) {
// Trying to get custom field from $entry
$field = $entry->getCustomField('field_id_325');
$value = $field->getData();
echo 'value field_id_325 - ' . $value;
// Trying to get custom field from $entry
print_r($values);
die('TESTING');
}
Everything is empty.
I was able to use a workaround by commenting the line:
107 in file /system/ee/EllisLab/ExpressionEngine/Model/Content/ContentModel.php
$this->deleteFieldData();
To prevent deleting data.
Then in the hook method I added:
$entry_tmp = ee('Model')->get('ChannelEntry', $entry->entry_id)->first();
$field = $entry_tmp->getCustomField('field_id_325');
$value = $field->getData();
echo 'value entry_tmp - ' . $value;
In this way I was able to see the value correctly. But I feel that this is not the best, also I don’t want to edit core code. Do you have any suggestions?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.