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

Allow usage object properties to get/set instance in ObjectManipulator #6534

Conversation

peter-gribanov
Copy link
Contributor

@peter-gribanov peter-gribanov commented Oct 23, 2020

Subject

Now the ObjectManipulator does not work correctly if you pass it a DTO without setters and getters and only with public properties.

https://github.com/sonata-project/SonataAdminBundle/pull/6171/files#r510937030

Not sure if this is related, but i got this exception after a recent update:

RuntimeException: Method PlaylistRelationAdminView::setPlaylist() does not exist.
#22 /vendor/sonata-project/admin-bundle/src/Manipulator/ObjectManipulator.php(106): Sonata\AdminBundle\Manipulator\ObjectManipulator::callSetter
#21 /vendor/sonata-project/admin-bundle/src/Manipulator/ObjectManipulator.php(67): Sonata\AdminBundle\Manipulator\ObjectManipulator::setObject
#20 /vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php(3566): Sonata\AdminBundle\Admin\AbstractAdmin::appendParentObject
#19 /vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php(1375): Sonata\AdminBundle\Admin\AbstractAdmin::getNewInstance
#18 /vendor/sonata-project/admin-bundle/src/Form/Type/AdminType.php(111): Sonata\AdminBundle\Form\Type\AdminType::buildForm
#17 /vendor/symfony/form/ResolvedFormType.php(128): Symfony\Component\Form\ResolvedFormType::buildForm
#16 /vendor/symfony/form/FormFactory.php(80): Symfony\Component\Form\FormFactory::createNamedBuilder
#15 /vendor/symfony/form/FormFactory.php(38): Symfony\Component\Form\FormFactory::createNamed
#14 /vendor/symfony/form/Form.php(866): Symfony\Component\Form\Form::add
#13 /vendor/sonata-project/form-extensions/src/EventListener/ResizeFormListener.php(149): Sonata\Form\EventListener\ResizeFormListener::preSubmit
#12 /vendor/symfony/event-dispatcher/EventDispatcher.php(264): Symfony\Component\EventDispatcher\EventDispatcher::doDispatch
#11 /vendor/symfony/event-dispatcher/EventDispatcher.php(239): Symfony\Component\EventDispatcher\EventDispatcher::callListeners
#10 /vendor/symfony/event-dispatcher/EventDispatcher.php(73): Symfony\Component\EventDispatcher\EventDispatcher::dispatch
#9 /vendor/symfony/event-dispatcher/ImmutableEventDispatcher.php(44): Symfony\Component\EventDispatcher\ImmutableEventDispatcher::dispatch
#8 /vendor/symfony/form/Form.php(558): Symfony\Component\Form\Form::submit
#7 /vendor/symfony/form/Form.php(579): Symfony\Component\Form\Form::submit
#6 /vendor/symfony/form/Extension/HttpFoundation/HttpFoundationRequestHandler.php(109): Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler::handleRequest
#5 /vendor/symfony/form/Form.php(493): Symfony\Component\Form\Form::handleRequest
#4 /vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php(319): Sonata\AdminBundle\Controller\CRUDController::editAction
#3 /vendor/symfony/http-kernel/HttpKernel.php(158): Symfony\Component\HttpKernel\HttpKernel::handleRaw
#2 /vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel::handle
#1 /vendor/symfony/http-kernel/Kernel.php(201): Symfony\Component\HttpKernel\Kernel::handle
#0 /web/app.php(53): null
class PlaylistRelationAdminView
{
    /**
     * @ORM\Column(name="position", type="integer", nullable=false)
     *
     * @var int
     */
    public int $position = 0;

    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     * @ORM\ManyToOne(targetEntity="PlaylistAdminView", inversedBy="relations")
     * @ORM\JoinColumn(name="playlist_id", referencedColumnName="id", nullable=false)
     */
    public ?PlaylistAdminView $playlist = null;

    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     * @ORM\ManyToOne(targetEntity="Video", inversedBy="admin_video_relations")
     * @ORM\JoinColumn(name="video_id", referencedColumnName="id", nullable=false)
     */
    public ?Video $video = null;
}

Changelog

### Fixed
- Allow usage object properties to get/set instance in ObjectManipulator

@peter-gribanov peter-gribanov force-pushed the ObjectManipulator_property_access branch from 8b339ea to 90f731a Compare October 23, 2020 15:40
src/Manipulator/ObjectManipulator.php Outdated Show resolved Hide resolved
src/Manipulator/ObjectManipulator.php Outdated Show resolved Hide resolved
@VincentLanglet
Copy link
Member

Could you also had tests, to avoid a futur regression :)

@peter-gribanov peter-gribanov force-pushed the ObjectManipulator_property_access branch from 90f731a to a7f9c3a Compare October 23, 2020 15:43
@VincentLanglet VincentLanglet requested a review from a team October 23, 2020 15:45
@VincentLanglet
Copy link
Member

Please take a look @sonata-project/contributors

@VincentLanglet
Copy link
Member

@peter-gribanov I just saw that there is no test for the callGetter method. Do you mind adding some ? :)

Will a full test-cover, I think I could merge this with only one review.

@peter-gribanov
Copy link
Contributor Author

@VincentLanglet test testSetObjectPropertyWithParentAssociation is testing callGetter.

@VincentLanglet VincentLanglet merged commit d1af47a into sonata-project:3.x Nov 2, 2020
@VincentLanglet
Copy link
Member

Thanks @peter-gribanov

@peter-gribanov peter-gribanov deleted the ObjectManipulator_property_access branch November 2, 2020 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants