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

[Bug]: Fix deletion of context.objectId #738

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

alexmarkop
Copy link
Contributor

@alexmarkop alexmarkop commented Oct 31, 2024

This code change fixes the mistaken deletion of "objectId" from "this.context".

Without this, the following example is broken:
https://pimcore.com/docs/platform/Pimcore/Extending_Pimcore/Event_API_and_Event_Manager/#asset-upload-path

Copy link

github-actions bot commented Oct 31, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copy link

@alexmarkop
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@alexmarkop alexmarkop changed the title Fix mistakenly deletion of context.objectId [Bug]: Fix deletion of context.objectId Nov 6, 2024
@mcop1 mcop1 self-assigned this Nov 15, 2024
@mcop1
Copy link
Contributor

mcop1 commented Nov 15, 2024

Hello @alexmarkop ,

could you please provide steps to reproduce the problem?

What I did was:

  • Create EventListener with code from documentation
  • Go to a news object
  • Upload a new asset to the gallery
  • Check if the asset was created in the expected folder
    image

Seems to be working for me. Did I miss something?

@alexmarkop
Copy link
Contributor Author

Hi @mcop1 ,
The issue was introduced by this commit:
80498ed
file public/js/pimcore/object/tags/abstractRelations.js line 212:

delete context.objectId;

Take a look at the code snippet in the following example (Asset Upload Path):
https://pimcore.com/docs/platform/Pimcore/Extending_Pimcore/Event_API_and_Event_Manager/#asset-upload-path

\Pimcore::getEventDispatcher()->addListener(AssetEvents::RESOLVE_UPLOAD_TARGET,
            function(\Pimcore\Event\Model\Asset\ResolveUploadTargetEvent $event) {
                $context = $event->getContext();
                if ($context["containerType"] == "object") {
                    $objectId = $context["objectId"];
                    $newsObject = News::getById($objectId);
                    if ($newsObject) {
                        $fieldname = $context["fieldname"];
                        $targetPath = $newsObject->getPath() . $newsObject->getKey() . "/" . $fieldname;
                        $parent = \Pimcore\Model\Asset\Service::createFolderByPath($targetPath);
                        if ($parent) {
                            $event->setParentId($parent->getId());
                        }
                    }

                }
        });

now $context["objectId"] is not available anymore causing the example above to throw an error.

@mcop1
Copy link
Contributor

mcop1 commented Nov 22, 2024

Thanks again for the fix!

Cherry picked to 1.6 with 77e046a

@mcop1 mcop1 merged commit f97192f into pimcore:1.x Nov 22, 2024
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2024
@mcop1 mcop1 added this to the 1.6.3 milestone Nov 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants