public function saveAction(Request $request)
    {
        $json_nodes = $request->get('nodes');

        if ($json_nodes) {
            $this->em = $this->getDoctrine()->getManager();

            foreach ($json_nodes as $id => $obj) {

                $contentNode = $this->em->find(ContentNode::class, $id);

                if ($contentNode) {

                    $className = $obj['class'];
                    unset($obj['class']);

                    $metaData = $this->getClassMetaData($className);

                    foreach ($obj as $key => $value) {

                        $method = 'set' . ucfirst($key);

                        if (method_exists($contentNode, $method)) {

                            if (!empty($metaData->associationMappings[$key])) {

                                $fieldMetaData = $metaData->associationMappings[$key];
                                $repo = $this->em->getRepository($fieldMetaData['targetEntity']);


                                //check if its just a standard relation
                                if (
                                in_array(
                                    $fieldMetaData['type'],
                                    array(
                                        ClassMetadataInfo::ONE_TO_MANY,
                                        ClassMetadataInfo::MANY_TO_MANY
                                    )
                                )
                                )
                                    $value = $repo->findById($value);
                                else
                                    $value = $repo->findOneById($value);

                            }

                            $contentNode->$method($value);
                        }
                    }

                    $this->em->persist($contentNode);
                }
            }

            $this->em->flush();

            return new JsonResponse(array('status' => 'saved'));
        } else {
            return new JsonResponse(array('status' => 'failed', 'msg' => 'Nothing to update.'));
        }

    }
public function saveAction(Request $request)
    {
        $json_nodes = $request->get('nodes');

        if ($json_nodes) {
            $this->em = $this->getDoctrine()->getManager();

            foreach ($json_nodes as $id => $obj) {

                $contentNode = $this->em->find(ContentNode::class, $id);

                if ($contentNode) {

                    $className = $obj['class'];
                    unset($obj['class']);

                    $metaData = $this->getClassMetaData($className);

                    foreach ($obj as $key => $value) {

                        $method = 'set' . ucfirst($key);

                        if (method_exists($contentNode, $method)) {

                            if (!empty($metaData->associationMappings[$key])) {

                                $fieldMetaData = $metaData->associationMappings[$key];
                                $repo = $this->em->getRepository($fieldMetaData['targetEntity']);


                                //check if its just a standard relation
                                if (
                                in_array(
                                    $fieldMetaData['type'],
                                    array(
                                        ClassMetadataInfo::ONE_TO_MANY,
                                        ClassMetadataInfo::MANY_TO_MANY
                                    )
                                )
                                )
                                    $value = $repo->findById($value);
                                else
                                    $value = $repo->findOneById($value);

                            }

                            $contentNode->$method($value);
                        }
                    }

                    $this->em->persist($contentNode);
                }
            }

            $this->em->flush();

            return new JsonResponse(array('status' => 'saved'));
        } else {
            return new JsonResponse(array('status' => 'failed', 'msg' => 'Nothing to update.'));
        }

    }
public function saveAction ( Request $ request ) { $ json_nodes = $ request -> get ( 'nodes' ) ; if ( $ json_nodes ) { $ this -> em = $ this -> getDoctrine ( ) -> getManager ( ) ; foreach ( $ json_nodes as $ id => $ obj ) { $ contentNode = $ this -> em -> find ( ContentNode :: class , $ id ) ; if ( $ contentNode ) { $ className = $ obj [ 'class' ] ; unset ( $ obj [ 'class' ] ) ; $ metaData = $ this -> getClassMetaData ( $ className ) ; foreach ( $ obj as $ key => $ value ) { $ method = 'set' . ucfirst ( $ key ) ; if ( method_exists ( $ contentNode , $ method ) ) { if ( ! empty ( $ metaData -> associationMappings [ $ key ] ) ) { $ fieldMetaData = $ metaData -> associationMappings [ $ key ] ; $ repo = $ this -> em -> getRepository ( $ fieldMetaData [ 'targetEntity' ] ) ; //check if its just a standard relation if ( in_array ( $ fieldMetaData [ 'type' ] , array ( ClassMetadataInfo :: ONE_TO_MANY , ClassMetadataInfo :: MANY_TO_MANY ) ) ) $ value = $ repo -> findById ( $ value ) ; else $ value = $ repo -> findOneById ( $ value ) ; } $ contentNode -> $ method ( $ value ) ; } } $ this -> em -> persist ( $ contentNode ) ; } } $ this -> em -> flush ( ) ; return new JsonResponse ( array ( 'status' => 'saved' ) ) ; } else { return new JsonResponse ( array ( 'status' => 'failed' , 'msg' => 'Nothing to update.' ) ) ; } }
AJAX save endpoint, not related to the CRUD

@param Request $request
@return JsonResponse
AJAX save endpoint not related to the CRUD