public function deleteEntryBySlug(string $sectionHandle, string $slug): JsonResponse
    {
        $request = $this->requestStack->getCurrentRequest();

        $optionsResponse = $this->preFlightOptions($request, self::ALLOWED_HTTP_METHODS);
        if ($optionsResponse) {
            return $optionsResponse;
        }

        $this->dispatcher->dispatch(
            ApiDeleteEntry::NAME,
            new ApiDeleteEntry($request, $sectionHandle)
        );

        if ($abort = $this->shouldAbort($request)) {
            return $abort;
        }

        try {
            $entry = $this->readSection->read(ReadOptions::fromArray([
                ReadOptions::SECTION => $sectionHandle,
                ReadOptions::SLUG => $slug
            ]))->current();
            $success = $this->deleteSection->delete($entry);
            $responseData = ['success' => $success];
            $jsonResponse = new JsonResponse(
                $responseData,
                $success ? JsonResponse::HTTP_OK : JsonResponse::HTTP_NOT_FOUND,
                $this->getDefaultResponseHeaders($request)
            );
            $this->dispatcher->dispatch(
                ApiEntryDeleted::NAME,
                new ApiEntryDeleted($request, $responseData, $jsonResponse, $entry)
            );

            if ($abort = $this->shouldAbort($request)) {
                return $abort;
            }

            return $jsonResponse;
        } catch (\Exception $exception) {
            return $this->errorResponse($request, $exception);
        }
    }
public function deleteEntryBySlug(string $sectionHandle, string $slug): JsonResponse
    {
        $request = $this->requestStack->getCurrentRequest();

        $optionsResponse = $this->preFlightOptions($request, self::ALLOWED_HTTP_METHODS);
        if ($optionsResponse) {
            return $optionsResponse;
        }

        $this->dispatcher->dispatch(
            ApiDeleteEntry::NAME,
            new ApiDeleteEntry($request, $sectionHandle)
        );

        if ($abort = $this->shouldAbort($request)) {
            return $abort;
        }

        try {
            $entry = $this->readSection->read(ReadOptions::fromArray([
                ReadOptions::SECTION => $sectionHandle,
                ReadOptions::SLUG => $slug
            ]))->current();
            $success = $this->deleteSection->delete($entry);
            $responseData = ['success' => $success];
            $jsonResponse = new JsonResponse(
                $responseData,
                $success ? JsonResponse::HTTP_OK : JsonResponse::HTTP_NOT_FOUND,
                $this->getDefaultResponseHeaders($request)
            );
            $this->dispatcher->dispatch(
                ApiEntryDeleted::NAME,
                new ApiEntryDeleted($request, $responseData, $jsonResponse, $entry)
            );

            if ($abort = $this->shouldAbort($request)) {
                return $abort;
            }

            return $jsonResponse;
        } catch (\Exception $exception) {
            return $this->errorResponse($request, $exception);
        }
    }
public function deleteEntryBySlug ( string $ sectionHandle , string $ slug ) : JsonResponse { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; $ optionsResponse = $ this -> preFlightOptions ( $ request , self :: ALLOWED_HTTP_METHODS ) ; if ( $ optionsResponse ) { return $ optionsResponse ; } $ this -> dispatcher -> dispatch ( ApiDeleteEntry :: NAME , new ApiDeleteEntry ( $ request , $ sectionHandle ) ) ; if ( $ abort = $ this -> shouldAbort ( $ request ) ) { return $ abort ; } try { $ entry = $ this -> readSection -> read ( ReadOptions :: fromArray ( [ ReadOptions :: SECTION => $ sectionHandle , ReadOptions :: SLUG => $ slug ] ) ) -> current ( ) ; $ success = $ this -> deleteSection -> delete ( $ entry ) ; $ responseData = [ 'success' => $ success ] ; $ jsonResponse = new JsonResponse ( $ responseData , $ success ? JsonResponse :: HTTP_OK : JsonResponse :: HTTP_NOT_FOUND , $ this -> getDefaultResponseHeaders ( $ request ) ) ; $ this -> dispatcher -> dispatch ( ApiEntryDeleted :: NAME , new ApiEntryDeleted ( $ request , $ responseData , $ jsonResponse , $ entry ) ) ; if ( $ abort = $ this -> shouldAbort ( $ request ) ) { return $ abort ; } return $ jsonResponse ; } catch ( \ Exception $ exception ) { return $ this -> errorResponse ( $ request , $ exception ) ; } }
DELETE an entry by it's slug
@param string $sectionHandle
@param string $slug
@return JsonResponse
DELETE an entry by it s slug