Могу ли я обновить сущность из несвязанного администратора Sonata

У меня есть объект "Запрос на бронирование" в методе "Администратор бронирования" getNewInstance, и я хочу обновить этот "Запрос на бронирование" ("Подтверждено") после сохранения нового бронирования.

    public function getNewInstance()
    {
        $instance = parent::getNewInstance();

        if ($this->hasRequest())
        {
            $bookingRequestId = $this->getRequest()->get('bookingRequestId', null);
            if($bookingRequestId)
            {
                $bookingRequestEntityManager = $this->modelManager->getEntityManager(BookingRequest::class);
                $bookingRequest = $bookingRequestEntityManager->getRepository(BookingRequest::class)->find($bookingRequestId);
            }
        }
        if (!$bookingRequest)
        {
            throw $this->createNotFoundException('Unable to find Booking Request.');
        }

        // Code here to load the Booking ($instance) object with Booking Request ($bookingRequest)

        //What I want to achieve is an update of $bookingRequest
        $bookingRequest->setConfirmed(true);

        return $instance;
    }

Я попытался получить доступ к Менеджеру сущностей запроса на бронирование из метода prePersist(..).

Я также попытался получить доступ к Менеджеру сущностей запросов на бронирование из переопределенного метода createAction(..).

    public function createAction(Request $request = NULL)
    {
        $result = parent::createAction();
        $bookingRequestId = $this->getRequest()->get('bookingRequestId', null);
        $bookingRequestEntityManager = $this->modelManager->getEntityManager(BookingRequest::class);
        $bookingRequest = $bookingRequestEntityManager->getRepository(BookingRequest::class)->find($bookingRequestId);

        if (!$bookingRequest) {
            throw $this->createNotFoundException('Unable to find Booking Request.');
        }

        return $result;
    }

Есть ли способ получить доступ к Администратору запроса на бронирование из Администратора бронирования, чтобы я мог обновить Запрос на бронирование?

0 ответов

Другие вопросы по тегам