-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Prevent false deprecation error for n to m associations #6411
Prevent false deprecation error for n to m associations #6411
Conversation
d23fbb3
to
4b3945d
Compare
5757950
to
90c6c5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are suggestions.
src/Controller/CRUDController.php
Outdated
@@ -1554,7 +1554,13 @@ private function checkParentChildAssociation(Request $request, object $object): | |||
$propertyAccessor = PropertyAccess::createPropertyAccessor(); | |||
$propertyPath = new PropertyPath($this->admin->getParentAssociationMapping()); | |||
|
|||
if ($parentAdmin->getObject($parentId) !== $propertyAccessor->getValue($object, $propertyPath)) { | |||
$parentObject = $parentAdmin->getObject($parentId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about calling this $parentAdminObject
? And the one below $parentObject
. To be honest, I can't come up with something better, but $parentObject
and $objectParent
sound strange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parentAdminObject
will be OK.
objectParent
is bad idea, use parentAdminAvailableObjects
instead.
src/Controller/CRUDController.php
Outdated
* | ||
* @return bool true when $haystack equals $needle or $haystack is iterable and contains $needle | ||
*/ | ||
private static function equalsOrInList(object $needle, $haystack): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it doesn't need $this
, is there any benefit to create it as static
?
Looking at the method name, what about:
private static function equalsOrInList(object $needle, $haystack): bool | |
private function hasParentChildAssociation(object $parent, $parentAssociation): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is static, it could be in another class instead of this big CRUDController.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO we can keep it in CRUDController
and add it to #6512.
Of course remove static.
Hi @jorrit, are you still interested in this PR ? |
Yes, sorry for not responding. Can you recommend a class to put the static method into? |
90c6c5d
to
869c460
Compare
cc @sonata-project/contributors ; Any idea ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jorrit I add some comments.
src/Controller/CRUDController.php
Outdated
* | ||
* @return bool true when $haystack equals $needle or $haystack is iterable and contains $needle | ||
*/ | ||
private static function equalsOrInList(object $needle, $haystack): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO we can keep it in CRUDController
and add it to #6512.
Of course remove static.
src/Controller/CRUDController.php
Outdated
@@ -1554,7 +1554,13 @@ private function checkParentChildAssociation(Request $request, object $object): | |||
$propertyAccessor = PropertyAccess::createPropertyAccessor(); | |||
$propertyPath = new PropertyPath($this->admin->getParentAssociationMapping()); | |||
|
|||
if ($parentAdmin->getObject($parentId) !== $propertyAccessor->getValue($object, $propertyPath)) { | |||
$parentObject = $parentAdmin->getObject($parentId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parentAdminObject
will be OK.
objectParent
is bad idea, use parentAdminAvailableObjects
instead.
869c460
to
2a6a064
Compare
@wbloszyk : thanks, I've made the changes you suggested. |
Please review @sonata-project/contributors @wbloszyk |
Thanks @jorrit |
Subject
CRUDController->checkParentChildAssociation()
checks if the associated item of the child admins subject equals the parent admins subject. This doesn't work when the parent relations is many-to-many as the child property will be a Collection and not the parent item itself. In that case, the parent item must be searched in this collection.I am targeting this branch, because its a backwards compatible fix.
Changelog