Coder Social home page Coder Social logo

Comments (4)

amyAMeQ avatar amyAMeQ commented on July 28, 2024

This is definitely a problem for us. My API uses entities from a shared library, and several entities have __clone functions that intentionally do not copy over the id. Things would be ok if the IRI wasn't generated based on previous data, but on current data.

from core.

amyAMeQ avatar amyAMeQ commented on July 28, 2024

OK. I have a work around for those of us who stubbornly wanted to update. You can decorate the WriteListener Here is my quick implementation. (I've just banged it out and not put it through any significant tests yet)

<?php

namespace App\EventListener;

use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Throwable;

#[AsDecorator('api_platform.listener.view.write')]
class WriteListener
{
    public function __construct(private \ApiPlatform\Symfony\EventListener\WriteListener $decorated)
    {
    }

    public function onKernelView(ViewEvent $event): void
    {
        $this->decorated->onKernelView($event);
        $data = $event->getControllerResult();
        $request = $event->getRequest();
        $method = $request->getMethod();
        if ('GET' === $method) {
            try {
                $originalData = $request->attributes->get('original_data');
                if ($data->getId() && !$originalData->getId()) {
                    $request->attributes->set('original_data', $data);
                }
            } catch (Throwable) {
            }
        }
    }
}

from core.

soyuka avatar soyuka commented on July 28, 2024

I'm not sure why is cloning original data even needed.

Thanks for the detailed report I'll fix this, indeed it looks like cloning is not needed there, can you confirm the patch solves your issue? Thanks.

from core.

ZZromanZZ avatar ZZromanZZ commented on July 28, 2024

@soyuka Works, thank you.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.