public function moveTagsAction(Request $request, Tag $parentTag = null)
    {
        $this->denyAccessUnlessGranted('ez:tags:edit');

        $tagIds = $request->request->has('Tags') ?
            $request->request->get('Tags') :
            $this->get('session')->get('ngtags_tag_ids');

        if (empty($tagIds)) {
            return $this->redirectToTag($parentTag);
        }

        $tags = [];
        foreach ($tagIds as $tagId) {
            $tags[] = $this->tagsService->loadTag($tagId);
        }

        $form = $this->createForm(
            MoveTagsType::class,
            [
                'parentTag' => $parentTag instanceof Tag ? $parentTag->id : 0,
            ],
            [
                'tags' => $tags,
                'action' => $request->getPathInfo(),
            ]
        );

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            try {
                $newParentTag = $this->tagsService->loadTag($form->getData()['parentTag']);
            } catch (NotFoundException $exception) {
                $newParentTag = null;
            }

            foreach ($tags as $tagObject) {
                $this->tagsService->moveSubtree($tagObject, $newParentTag);
            }

            $this->addFlashMessage('success', 'tags_moved');

            return $this->redirectToTag($parentTag);
        }

        return $this->render(
            '@NetgenTags/admin/tag/move_tags.html.twig',
            [
                'parentTag' => $parentTag ?: null,
                'tags' => $tags,
                'form' => $form->createView(),
            ]
        );
    }
public function moveTagsAction(Request $request, Tag $parentTag = null)
    {
        $this->denyAccessUnlessGranted('ez:tags:edit');

        $tagIds = $request->request->has('Tags') ?
            $request->request->get('Tags') :
            $this->get('session')->get('ngtags_tag_ids');

        if (empty($tagIds)) {
            return $this->redirectToTag($parentTag);
        }

        $tags = [];
        foreach ($tagIds as $tagId) {
            $tags[] = $this->tagsService->loadTag($tagId);
        }

        $form = $this->createForm(
            MoveTagsType::class,
            [
                'parentTag' => $parentTag instanceof Tag ? $parentTag->id : 0,
            ],
            [
                'tags' => $tags,
                'action' => $request->getPathInfo(),
            ]
        );

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            try {
                $newParentTag = $this->tagsService->loadTag($form->getData()['parentTag']);
            } catch (NotFoundException $exception) {
                $newParentTag = null;
            }

            foreach ($tags as $tagObject) {
                $this->tagsService->moveSubtree($tagObject, $newParentTag);
            }

            $this->addFlashMessage('success', 'tags_moved');

            return $this->redirectToTag($parentTag);
        }

        return $this->render(
            '@NetgenTags/admin/tag/move_tags.html.twig',
            [
                'parentTag' => $parentTag ?: null,
                'tags' => $tags,
                'form' => $form->createView(),
            ]
        );
    }
public function moveTagsAction ( Request $ request , Tag $ parentTag = null ) { $ this -> denyAccessUnlessGranted ( 'ez:tags:edit' ) ; $ tagIds = $ request -> request -> has ( 'Tags' ) ? $ request -> request -> get ( 'Tags' ) : $ this -> get ( 'session' ) -> get ( 'ngtags_tag_ids' ) ; if ( empty ( $ tagIds ) ) { return $ this -> redirectToTag ( $ parentTag ) ; } $ tags = [ ] ; foreach ( $ tagIds as $ tagId ) { $ tags [ ] = $ this -> tagsService -> loadTag ( $ tagId ) ; } $ form = $ this -> createForm ( MoveTagsType :: class , [ 'parentTag' => $ parentTag instanceof Tag ? $ parentTag -> id : 0 , ] , [ 'tags' => $ tags , 'action' => $ request -> getPathInfo ( ) , ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { try { $ newParentTag = $ this -> tagsService -> loadTag ( $ form -> getData ( ) [ 'parentTag' ] ) ; } catch ( NotFoundException $ exception ) { $ newParentTag = null ; } foreach ( $ tags as $ tagObject ) { $ this -> tagsService -> moveSubtree ( $ tagObject , $ newParentTag ) ; } $ this -> addFlashMessage ( 'success' , 'tags_moved' ) ; return $ this -> redirectToTag ( $ parentTag ) ; } return $ this -> render ( '@NetgenTags/admin/tag/move_tags.html.twig' , [ 'parentTag' => $ parentTag ? : null , 'tags' => $ tags , 'form' => $ form -> createView ( ) , ] ) ; }
This method is called from a form containing all children tags of a tag.
It shows a confirmation view.
If form has been submitted, it moves selected children and all its children tags to a new parent.

@param \Symfony\Component\HttpFoundation\Request $request
@param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $parentTag

@return \Symfony\Component\HttpFoundation\Response
This method is called from a form containing all children tags of a tag . It shows a confirmation view . If form has been submitted it moves selected children and all its children tags to a new parent .