I have created an event that is called on beforeSave within my plugin. Code below:

        function(ModelEvent $event){
            /** @var Entry $entry */
            $entry = $event->sender;

            if($entry->section == 'Question' && $entry->type=='reply') {
                if($entry->newParentId != $entry->question->id[0]){
                    $entry->newParentId = $entry->question->id[0];

I can change things like title and that works fine but the parent will never set. I have even added the following to see if this helps but it doesn't

if ($entry->newParentId) {
    $parentEntry = Craft::$app->getEntries()->getEntryById($entry->newParentId, $entry->siteId);
    if (!$parentEntry) {
         throw new Exception('Invalid entry ID: ' . $entry->newParentId);
} else {
    $parentEntry = null;


Please Note: This is not a custom element!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.