sulu / SuluArticleBundle

Bundle for managing localized content-rich entities like blog-posts in the Sulu content management system
MIT License
52 stars 77 forks source link

Create new locale of an article always copies content from previous locale. #646

Closed Quehnie closed 5 months ago

Quehnie commented 10 months ago
Q A
Bug? yes
New Feature? no
SuluArticleBundle Version 2.5.0
Sulu Version 2.5.9

Actual Behavior

If i have an article in a local like EN and i want create a new locale for this article -> switching to DE. A popup occurs which asks me if i want to copy the content from another locale, but if i press "NO" the content from the previous locale is still in the document.

Expected Behavior

That the popup respects my opinion ^^

Steps to Reproduce

Create webspace with two locales, create an article in the article bundle and switch to the other locale, then press "no" on the popup.

Possible Solutions

In the ArticleController we should add the 'load_ghost_content' => false and 'structure_type' => 'templateKey' to the options. we dont have a "default article template" yet so maybe implement this or search for the ghost_content and use the same structure key as the ghost locale. overwrite it like that in a project of mine.

public function getAction(Request $request, string $id): Response
    {
        $locale = $this->getRequestParameter($request, 'locale', true);
        $ghostContent = $this->getBooleanRequestParameter($request, 'ghost-content', false, false);

        /** @var ArticleDocument $document */
        $document = $this->documentManager->find(
            $id,
            $locale,
            [
                'load_ghost_content' => $ghostContent,
            ]
        );

        if (null === $document->getStructureType()) {
            $ghostDocument = $this->documentManager->find(
                $id,
                $locale
            );

            $document = $this->documentManager->find(
                $id,
                $locale,
                [
                    'load_ghost_content' => $ghostContent,
                    'structure_type' => $ghostDocument->getStructureType(),
                ]
            );
        }

        $context = new Context();
        $context->setSerializeNull(true);
        $context->setGroups(['defaultPage', 'defaultArticle', 'smallArticlePage']);

        return $this->handleView(
            $this->view($document)->setContext($context)
        );
    }
Quehnie commented 5 months ago

Fixed with https://github.com/sulu/SuluArticleBundle/releases/tag/2.5.2