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]: broken versions when converting data component from many-to-many-object to advanced-many-to-many-object #16977

Open
svdv22 opened this issue Apr 23, 2024 · 2 comments
Labels

Comments

@svdv22
Copy link
Contributor

svdv22 commented Apr 23, 2024

Pimcore version

tested on 10.5.22, but possibly all?

Steps to reproduce

  1. Create a new class
  2. Add a data component of type many-to-many-object
  3. Create a data object of your newly created class, add some data to the field
  4. Change the data component to advanced-many-to-many-object
  5. Open the penultimate version of the data object, you'll see an error

Actual Behavior

You will see an error:

An exception has been thrown during the rendering of a template ("Call to undefined method getElement in class <fqcn of data object you added in the relation field>").

This is caused by [line 412 in models/DataObject/ClassDefinition/Data/AdvancedManyToManyRelation.php#L412]

Expected Behavior

Preferably that it shows the already existing objects (and the rest of the data in that version). If that's not possible just show the rest of that version with no data anymore for that data component.

@svdv22 svdv22 added the Bug label Apr 23, 2024
@svdv22
Copy link
Contributor Author

svdv22 commented Apr 23, 2024

Adding a check to see if the method exists is easy enough. But as far as I understand changing the code so that the objects are still visible shouldn't be too hard either.

First get the actual object:


if (\method_exists($metaObject, 'getElement')) {
    $o = $metaObject->getElement();
} elseif ($metaObject instanceof DataObject) {
    $o = $metaObject;
}

Then later on it will loop over the data, that does not exist. So we can just do another method_exists and have a fallback on an empty array:

$data = [];
if (\method_exists($metaObject, 'getData')) {
    $data = $metaObject->getData();
}

This way the version is working again.

If you agree I can create a PR

@svdv22
Copy link
Contributor Author

svdv22 commented Apr 23, 2024

On second thought, it's perhaps a bit weird to add exceptions in the code base of AdvancedManyToManyRelation. I get a lot of hits when I search for 'getPreviewData', but as far as I can see we can also fix this issue with an extra definition is instanceof(...) check in previewVersion.html.twig

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

No branches or pull requests

1 participant