Delete an Element.

@param Request $request

@return ResultResponse
@Route("/delete", name="tree_delete")
514595
public function deleteAction(Request $request)
    {
        $treeIds = $request->get('id');
        if (!is_array($treeIds)) {
            $treeIds = [$treeIds];
        }

        $treeManager = $this->get('phlexible_tree.tree_manager');

        foreach ($treeIds as $treeId) {
            $tree = $treeManager->getByNodeId($treeId);
            $node = $tree->get($treeId);

            $tree->delete($node, $this->getUser()->getId());
        }

        return new ResultResponse(true, 'Item(s) deleted');
    }
302652
public function destroy($id, Request $request)
    {
        $model = $this->model();

        $force = false;
        if (method_exists($model, 'forceDelete')) {
            $this->validate($request, ['force' => ['boolean']]);

            $model = $model->withTrashed();
            $force = (bool) $request->input('force');
        }

        return $this->deleteModel($model->find($id), 'delete', $force);
    }
1071163
public function deleteAction(Request $request, $id)
    {
        $this->checkIfUserHasPermission(Permission::CREATE_DELETE);

        $this->getParentEntityDefinition($request);

        $entity = $this->getEntity($id);

        $this->getEventDispatcher()->dispatch(
            Events::PRE_CRUD_CONTROLLER_ACTION,
            new CrudControllerActionEvent($this->meta, __FUNCTION__)
        );

        $form = $this->getAdminFormFactory()->createDeleteForm($entity, $this->entityClass)->handleRequest($request);

        if ($this->getFormHandler()->handleDeleteForm($form, $entity)) {
            $this->getEventDispatcher()->dispatch(CrudEvents::DELETED, new DeletedEvent($this->getUser(), $entity));

            return $this->redirect($this->getAdminRouter()->generate($entity, $this->entityClass, AdminRouter::TYPE_INDEX));
        }

        $url = $request->headers->get(
            'referer',
            $this->getAdminRouter()->generate($entity, $this->entityClass, AdminRouter::TYPE_INDEX)
        );

        return $this->redirect($url);
    }
1129133
public function deleteMedia(Request $request)
    {
        // if single file/folder '?s=name'
        if ($request->has('s')) {
            if (is_dir(storage_path('app') . DIRECTORY_SEPARATOR . $request->input('s'))) {
                return $this->deleteDirectory($request);
            } else {
                return $this->deleteFile($request);
            }
        }

        // if multiple files
        if ($request->has('files')) {
            Storage::delete($request->input('files'));
        }

        // if multiple directories
        if ($request->has('directories')) {
            if (is_array($request->input('directories'))) {
                foreach ($request->input('directories') as $directory) {
                    Storage::deleteDirectory($directory);
                }
            } else {
                Storage::deleteDirectory($request->input('directories'));
            }
        }

        if ($request->wantsJson()) {
            return $this->notifySuccess('File/Folder deleted successfully!');
        }

        flash()->success('File/Folder deleted successfully!');

        return redirect()->back();
    }
1013528
public function deleteAction(Request $request)
    {
        if ($this->submitForm($this->buildForm(CsrfProtectionType::class), $request)->isValid()) {
            try {
                $this->getDomainManager()->delete($this->find('delete'));
            } catch (DomainException $e) {
                $this->processException($e);
            }
        }

        return $this->processAction('delete');
    }
646290
public function userDeleteAction(Request $request): Response
    {
        $form = $this->formFactory->deleteUser();

        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (UserDeleteData $data) {
                $contentInfo = $data->getContentInfo();

                $location = $this->locationService->loadLocation($contentInfo->mainLocationId);

                $user = $this->userService->loadUser($contentInfo->id);

                $this->userService->deleteUser($user);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("User with login '%login%' deleted.") */
                        'user.delete.success',
                        ['%login%' => $user->login],
                        'content'
                    )
                );

                return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
                    'locationId' => $location->parentLocationId,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('ezplatform.dashboard'));
    }
1299657
public function bulkDelete(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Permissions', 'delete')) {
            return $this->noPermission();
        }
        $data = $request->all();
        if(isset($data['postTypes'])) {
            unset($data['postTypes']);
        }

        DB::statement('SET FOREIGN_KEY_CHECKS=0');
        foreach ($data as $id){
            $page = \App\Models\UserGroup::findOrFail($id)->delete();
            if (!$page) {
                return $this->response('Internal server error. Please try again later', 500);
            }
            DB::table('permissions')->where('groupID', $id)->delete();
        }

        return $this->response('Groups are deleted');
    }
890164
public function delete_item( $request ) {

		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;

		// We don't support trashing for this resource type.
		if ( ! $force ) {
			return new WP_Error( 'rest_trash_not_supported', __( 'Resource does not support trashing.' ), array( 'status' => 501 ) );
		}

		$term = get_term( (int) $request['id'], $this->taxonomy );
		$request->set_param( 'context', 'view' );
		$response = $this->prepare_item_for_response( $term, $request );

		$retval = wp_delete_term( $term->term_id, $term->taxonomy );
		if ( ! $retval ) {
			return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) );
		}

		/**
		 * Fires after a single term is deleted via the REST API.
		 *
		 * @param WP_Term          $term     The deleted term.
		 * @param WP_REST_Response $response The response data.
		 * @param WP_REST_Request  $request  The request sent to the API.
		 */
		do_action( "rest_delete_{$this->taxonomy}", $term, $response, $request );

		return $response;
	}
1316398
public function cdeleteAction(Request $request)
    {
        $repository = $this->getRedirectRouteRepository();
        $manager = $this->getRedirectRouteManager();

        $ids = array_filter(explode(',', $request->query->get('ids', '')));
        foreach ($ids as $id) {
            $redirectRoute = $repository->find($id);
            if (!$redirectRoute) {
                continue;
            }

            $manager->delete($redirectRoute);
        }

        $this->get('doctrine.orm.entity_manager')->flush();

        return $this->handleView($this->view());
    }
167850
public function bulkDelete(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('PostType', 'delete')) {
            return $this->noPermission();
        }
        // if there are no item selected
        if (count($request->all()) <= 0) {
            return $this->response('Please select items to be deleted', 500);
        }

        // loop throw the item array (ids) and delete them
        foreach($request->all() as $id){
            $res = $this->deletePostType($id);
            if(!$res) {
                return $this->response('Post Type could not be deleted. Please try again later or contact your Administrator!', 500);
            }
            if(!is_bool($res)) {
                return $res;
            }
        }
        return $this->response('Selected post types are successfully deleted', 200);
    }
541144
public function removeAction(Request $request)
    {
        $container = $this->findContainerByRequest($request);
        $content = $container->getContent();

        try {
            $this->getEditor()->getContainerManager()->delete($container);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        // Stores id for front removal
        $removedId = $this->getViewBuilder()->buildContainer($container)->getAttributes()->getId();

        $this->validate($content);
        $this->persist($content);

        $data = [
            'removed' => [$removedId],
            //'contents' => [$this->getViewBuilder()->buildContent($content)],
        ];

        return $this->buildResponse($data, self::SERIALIZE_LAYOUT);
    }
1021296
public function handle(Model $eloquent, Request $request)
    {
        return $this->fetchForDelete($eloquent, $request)
                    ->each(function ($item) {
                        return $this->canDelete($item) ? $item->delete() : $item;
                    });
    }
800440
public function deleteAction(Request $request, $id)
    {
        $language = $this->getLanguage($request);
        $webspace = $this->getWebspace($request);
        $force = $this->getBooleanRequestParameter($request, 'force', false, false);

        if (!$force) {
            $references = array_filter(
                $this->getRepository()->getReferences($id),
                function(PropertyInterface $reference) {
                    return $reference->getParent()->isNodeType('sulu:page');
                }
            );

            if (count($references) > 0) {
                $data = [
                    'structures' => [],
                    'other' => [],
                ];

                foreach ($references as $reference) {
                    $content = $this->get('sulu.content.mapper')->load(
                        $reference->getParent()->getIdentifier(),
                        $webspace,
                        $language,
                        true
                    );
                    $data['structures'][] = $content->toArray();
                }

                return $this->handleView($this->view($data, 409));
            }
        }

        $view = $this->responseDelete(
            $id,
            function($id) use ($webspace) {
                try {
                    $this->getRepository()->deleteNode($id, $webspace);
                } catch (DocumentNotFoundException $ex) {
                    throw new EntityNotFoundException('Content', $id);
                }
            }
        );

        return $this->handleView($view);
    }
1081471
public function childelementsAction(Request $request)
    {
        $id = $request->get('id');
        $language = $request->get('language');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $elementService = $this->get('phlexible_element.element_service');
        $iconResolver = $this->get('phlexible_element.icon_resolver');

        $tree = $treeManager->getByNodeID($id);
        $node = $tree->get($id);
        $eid = $node->getTypeId();
        $element = $elementService->findElement($eid);

        if (!$language) {
            $language = $element->getMasterLanguage();
        }

        $firstString = $this->get('translator')->trans('elements.first', [], 'gui');

        $data = [];
        $data[] = [
            'id' => '0',
            'title' => $firstString,
            'icon' => $iconResolver->resolveIcon('_top.gif'),
        ];

        foreach ($tree->getChildren($node) as $childNode) {
            $childElement = $elementService->findElement($childNode->getTypeId());
            $childElementVersion = $elementService->findLatestElementVersion($childElement);

            $data[] = [
                'id' => $childNode->getId(),
                'title' => $childElementVersion->getBackendTitle($language, $childElementVersion->getElement()->getMasterLanguage()).' ['.$childNode->getId().']',
                'icon' => $iconResolver->resolveTreeNode($childNode, $language),
            ];
        }

        return new JsonResponse(['elements' => $data]);
    }
382783
public function elementsAction(Request $request)
    {
        $siterootId = $request->get('siteroot_id');
        $language = $request->get('language');
        $query = $request->get('query');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $iconResolver = $this->get('phlexible_element.icon_resolver');
        $conn = $this->get('database_connection');

        $tree = $treeManager->getBySiteRootId($siterootId);

        $qb = $conn->createQueryBuilder();
        $qb
            ->select('t.id AS tid', 'e.latest_version AS version', 'evmf.backend AS title')
            ->from('tree', 't')
            ->join('t', 'element', 'e', 't.type_id = e.eid')
            ->join('e', 'element_version', 'ev', 'ev.eid = e.eid AND ev.version = e.latest_version')
            ->join('ev', 'element_version_mapped_field', 'evmf', 'evmf.element_version_id = ev.id')
            ->where($qb->expr()->eq('evmf.language', $qb->expr()->literal($language)))
            ->andWhere($qb->expr()->eq('t.siteroot_id', $qb->expr()->literal($siterootId)))
            ->andWhere($qb->expr()->like('evmf.backend', $qb->expr()->literal("%$query%")));

        $result = $conn->fetchAll($qb->getSQL());

        foreach ($result as $key => $row) {
            $treeNode = $tree->get($row['tid']);
            $result[$key]['icon'] = $iconResolver->resolveTreeNode($treeNode, $language);
        }

        return new JsonResponse(['results' => $result]);
    }
47019
public function moveAction(Request $request)
    {
        $id = $request->get('id');
        $targetId = $request->get('target');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $tree = $treeManager->getByNodeId($id);
        $node = $tree->get($id);

        $targetTree = $treeManager->getByNodeId($targetId);
        $targetNode = $tree->get($targetId);

        if ($id === $targetId) {
            return new ResultResponse(false, 'source_id === target_id');
        }

        $tree->move($node, $targetNode, $this->getUser()->getId());

        return new ResultResponse(true, 'Element moved.', ['id' => $id, 'parent_id' => $targetId]);
    }
1181150
public function deleteAction(Request $request)
    {
        $teaserId = $request->get('teaser_id');

        $teaserManager = $this->get('phlexible_teaser.teaser_manager');

        $teaser = $teaserManager->find($teaserId);

        $teaserManager->deleteTeaser($teaser, $this->getUser()->getId());

        return new ResultResponse(true, "Teaser {$teaser->getId()} deleted.");
    }