We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Support Find a Developer Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Support Find a Developer Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Get custom field entry data on before_channel_entry_delete hook

Development and Programming

Alberto Priore's avatar
Alberto Priore
2 posts
6 months ago
Alberto Priore's avatar Alberto Priore

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?

       
Alberto Priore's avatar
Alberto Priore
2 posts
6 months ago
Alberto Priore's avatar Alberto Priore

(Don’t look at the added “’;” and “</pre>” in the post. I don’t know why they are there posting the markdown text here)

       
Robin Sowell's avatar
Robin Sowell
13,142 posts
6 months ago
Robin Sowell's avatar Robin Sowell

Hrm- everything seems ok and I did a quick test on mine and the data are all there.

I’d dropped you an email, let’s see if we can figure this out.

       
Robin Sowell's avatar
Robin Sowell
13,142 posts
about 6 months ago
Robin Sowell's avatar Robin Sowell

I’m not going to be able to fix this one now, but I have put it into the bug tracker. The data should be there per the docs and it’s not- for the reason you pointed out.

See: https://github.com/ExpressionEngine/ExpressionEngine/issues/487

       

Reply

Sign In To Reply

ExpressionEngine Home Features Contact
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.