public function translationAction(Request $request, Tag $tag)
    {
        $this->denyAccessUnlessGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : ''));

        if (!$this->isCsrfTokenValid('eztags_admin', $request->request->get('_csrf_token'))) {
            $this->addFlashMessage('errors', 'invalid_csrf_token');

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

        $tagUpdateStruct = $this->tagsService->newTagUpdateStruct();

        if ($request->request->has('RemoveTranslationButton')) {
            if (empty($request->request->get('Locale'))) {
                $this->addFlashMessage('errors', 'no_translation_selected');

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

            $locales = $request->request->get('Locale');

            $newKeywords = $tag->keywords;

            foreach ($locales as $locale) {
                if (!isset($newKeywords[$locale])) {
                    $this->addFlashMessage('errors', 'no_translation', ['%locale%' => $locale]);
                } elseif ($locale === $tag->mainLanguageCode) {
                    $this->addFlashMessage('errors', 'main_translation');
                } else {
                    unset($newKeywords[$locale]);

                    $tagUpdateStruct = $this->tagsService->newTagUpdateStruct();

                    foreach ($newKeywords as $languageCode => $keyword) {
                        $tagUpdateStruct->setKeyword($keyword, $languageCode);
                    }

                    $this->tagsService->updateTag($tag, $tagUpdateStruct);

                    $this->addFlashMessage('success', 'translation_removed');
                }
            }
        } elseif ($request->request->has('UpdateMainTranslationButton')) {
            $newMainTranslation = $request->request->get('MainLocale');

            if (!in_array($newMainTranslation, $tag->languageCodes, true)) {
                $this->addFlashMessage('errors', 'no_translation', ['%locale%', $newMainTranslation]);
            } else {
                $tagUpdateStruct->mainLanguageCode = $newMainTranslation;
                $this->tagsService->updateTag($tag, $tagUpdateStruct);

                $this->addFlashMessage('success', 'main_translation_set', ['%locale%' => $newMainTranslation]);
            }
        } elseif ($request->request->has('UpdateAlwaysAvailableButton')) {
            $tagUpdateStruct->alwaysAvailable = (bool) $request->request->get('AlwaysAvailable');
            $this->tagsService->updateTag($tag, $tagUpdateStruct);

            $this->addFlashMessage('success', 'always_available_set');
        }

        return $this->redirectToTag($tag);
    }
public function translationAction(Request $request, Tag $tag)
    {
        $this->denyAccessUnlessGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : ''));

        if (!$this->isCsrfTokenValid('eztags_admin', $request->request->get('_csrf_token'))) {
            $this->addFlashMessage('errors', 'invalid_csrf_token');

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

        $tagUpdateStruct = $this->tagsService->newTagUpdateStruct();

        if ($request->request->has('RemoveTranslationButton')) {
            if (empty($request->request->get('Locale'))) {
                $this->addFlashMessage('errors', 'no_translation_selected');

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

            $locales = $request->request->get('Locale');

            $newKeywords = $tag->keywords;

            foreach ($locales as $locale) {
                if (!isset($newKeywords[$locale])) {
                    $this->addFlashMessage('errors', 'no_translation', ['%locale%' => $locale]);
                } elseif ($locale === $tag->mainLanguageCode) {
                    $this->addFlashMessage('errors', 'main_translation');
                } else {
                    unset($newKeywords[$locale]);

                    $tagUpdateStruct = $this->tagsService->newTagUpdateStruct();

                    foreach ($newKeywords as $languageCode => $keyword) {
                        $tagUpdateStruct->setKeyword($keyword, $languageCode);
                    }

                    $this->tagsService->updateTag($tag, $tagUpdateStruct);

                    $this->addFlashMessage('success', 'translation_removed');
                }
            }
        } elseif ($request->request->has('UpdateMainTranslationButton')) {
            $newMainTranslation = $request->request->get('MainLocale');

            if (!in_array($newMainTranslation, $tag->languageCodes, true)) {
                $this->addFlashMessage('errors', 'no_translation', ['%locale%', $newMainTranslation]);
            } else {
                $tagUpdateStruct->mainLanguageCode = $newMainTranslation;
                $this->tagsService->updateTag($tag, $tagUpdateStruct);

                $this->addFlashMessage('success', 'main_translation_set', ['%locale%' => $newMainTranslation]);
            }
        } elseif ($request->request->has('UpdateAlwaysAvailableButton')) {
            $tagUpdateStruct->alwaysAvailable = (bool) $request->request->get('AlwaysAvailable');
            $this->tagsService->updateTag($tag, $tagUpdateStruct);

            $this->addFlashMessage('success', 'always_available_set');
        }

        return $this->redirectToTag($tag);
    }
public function translationAction ( Request $ request , Tag $ tag ) { $ this -> denyAccessUnlessGranted ( 'ez:tags:edit' . ( $ tag -> isSynonym ( ) ? 'synonym' : '' ) ) ; if ( ! $ this -> isCsrfTokenValid ( 'eztags_admin' , $ request -> request -> get ( '_csrf_token' ) ) ) { $ this -> addFlashMessage ( 'errors' , 'invalid_csrf_token' ) ; return $ this -> redirectToTag ( $ tag ) ; } $ tagUpdateStruct = $ this -> tagsService -> newTagUpdateStruct ( ) ; if ( $ request -> request -> has ( 'RemoveTranslationButton' ) ) { if ( empty ( $ request -> request -> get ( 'Locale' ) ) ) { $ this -> addFlashMessage ( 'errors' , 'no_translation_selected' ) ; return $ this -> redirectToTag ( $ tag ) ; } $ locales = $ request -> request -> get ( 'Locale' ) ; $ newKeywords = $ tag -> keywords ; foreach ( $ locales as $ locale ) { if ( ! isset ( $ newKeywords [ $ locale ] ) ) { $ this -> addFlashMessage ( 'errors' , 'no_translation' , [ '%locale%' => $ locale ] ) ; } elseif ( $ locale === $ tag -> mainLanguageCode ) { $ this -> addFlashMessage ( 'errors' , 'main_translation' ) ; } else { unset ( $ newKeywords [ $ locale ] ) ; $ tagUpdateStruct = $ this -> tagsService -> newTagUpdateStruct ( ) ; foreach ( $ newKeywords as $ languageCode => $ keyword ) { $ tagUpdateStruct -> setKeyword ( $ keyword , $ languageCode ) ; } $ this -> tagsService -> updateTag ( $ tag , $ tagUpdateStruct ) ; $ this -> addFlashMessage ( 'success' , 'translation_removed' ) ; } } } elseif ( $ request -> request -> has ( 'UpdateMainTranslationButton' ) ) { $ newMainTranslation = $ request -> request -> get ( 'MainLocale' ) ; if ( ! in_array ( $ newMainTranslation , $ tag -> languageCodes , true ) ) { $ this -> addFlashMessage ( 'errors' , 'no_translation' , [ '%locale%' , $ newMainTranslation ] ) ; } else { $ tagUpdateStruct -> mainLanguageCode = $ newMainTranslation ; $ this -> tagsService -> updateTag ( $ tag , $ tagUpdateStruct ) ; $ this -> addFlashMessage ( 'success' , 'main_translation_set' , [ '%locale%' => $ newMainTranslation ] ) ; } } elseif ( $ request -> request -> has ( 'UpdateAlwaysAvailableButton' ) ) { $ tagUpdateStruct -> alwaysAvailable = ( bool ) $ request -> request -> get ( 'AlwaysAvailable' ) ; $ this -> tagsService -> updateTag ( $ tag , $ tagUpdateStruct ) ; $ this -> addFlashMessage ( 'success' , 'always_available_set' ) ; } return $ this -> redirectToTag ( $ tag ) ; }
This method is called from a form with each tag or synonym's translations table.
An action is defined with one of the three buttons in form which can be pressed.
It can remove selected translation, set it as main language, or set AlwaysAvailable property of a tag.

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

@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
This method is called from a form with each tag or synonym s translations table . An action is defined with one of the three buttons in form which can be pressed . It can remove selected translation set it as main language or set AlwaysAvailable property of a tag .