frankmullenger / silverstripe-gallery

Image gallery for SilverStripe 3
23 stars 17 forks source link

PHP Notice when editing related image #10

Open StephanSchrade opened 10 years ago

StephanSchrade commented 10 years ago

If I want to edit a related image to a page I get the following PHP Notice and can't get any further: [Notice] Trying to get property of non-object GET /admin/pages/edit/EditForm/field/Images/item/5/edit?locale=de_DE Line 378 in /Applications/XAMPP/xamppfiles/htdocs/gallery/code/GalleryUploadField.php

I'm using the module "translatable" in SS 3.1.2

frankmullenger commented 10 years ago

@StephanSchrade looks like it might be trying to access the Caption field on the join table/object. You might need to define that join object for your particular page class e.g: https://github.com/frankmullenger/silverstripe-gallery/blob/1.1/code/GalleryPage.php#L20. Or perhaps a /dev/build.

Can you update if that fixes the issue, or if this issue doesn't exist on GalleryPage type pages?

3Dgoo commented 8 years ago

I am able to recreate this issue.

To recreate this issue add a new image to a gallery page, click edit on the new image, click save on the image.

An error occurs because the many to many instance between the gallery page and the image has not been saved to the database yet. This does not happen until the page is saved / published. Editing and saving the image tries to save the Caption variable, which is on the GalleryPage_Images table and which does not exist for this instance yet.

The page needs to be saved before the new images can be edited.

Is there something we can do with the code to fix or avoid this problem?

One way to avoid to problem would be to hide the Edit button until the page is saved and the many_many relationship instance exists.