Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when publishing draft on an entry that is cloned/duplicated #73

Closed
Joobs opened this issue Mar 25, 2021 · 2 comments
Closed

Error when publishing draft on an entry that is cloned/duplicated #73

Joobs opened this issue Mar 25, 2021 · 2 comments

Comments

@Joobs
Copy link

Joobs commented Mar 25, 2021

Craft 3.6.11.1, Preparse 1.2.4

If I clone/duplicate an entry, and then try and publish a draft from that cloned entry I get the following error:

PHP Notice – yii\base\ErrorException
Trying to get property 'id' of non-object

1. in /app/cms/vendor/besteadfast/craft-preparse-field/src/PreparseField.phpat line 118
function (ElementEvent $event) {
                if ($event->element->getIsRevision()) {
                    return;
                }
 
                if ($event->element->getId()) {
                    // Since it's already been saved, we need to fetch the element again.
                    /** @var Element $element */
                    $element = Craft::$app->elements->getElementById($event->element->getId(), null, $event->element->siteId);
                    $key = $element->id . '__' . $element->siteId;
 
                    if (!isset($this->preparsedElements['onSave'][$key])) {
                        $this->preparsedElements['onSave'][$key] = true;
 
                        // Still pass the event element here to generate the preparse fields content, not the $element fetched above.
                        $content = self::$plugin->preparseFieldService->getPreparseFieldsContent($event->element, 'onSave');
 
                        if (!empty($content)) {
                            $this->resetUploads();

Screenshot 2021-03-25 at 20 21 33

I've seen the Trying to get property 'id' of non-object mentioned in a few other recent issues. Any idea how to fix?

@jalendport
Copy link
Owner

Hey, just wanted to let you know that we've found a potential solution for this; just want to do some testing and maybe get some additional eyes on it from some people that are much smarter than I am so we don't cause a regression for #66. Look for something early next week 🤞

@jalendport
Copy link
Owner

Just released version 1.2.5 which fixes this bug 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants