diff --git a/Controller/ArticleController.php b/Controller/ArticleController.php
index 500b2ae0..806edcbc 100644
--- a/Controller/ArticleController.php
+++ b/Controller/ArticleController.php
@@ -31,6 +31,8 @@
use Sulu\Bundle\ArticleBundle\Document\Index\DocumentFactoryInterface;
use Sulu\Bundle\ArticleBundle\ListBuilder\ElasticSearchFieldDescriptor;
use Sulu\Bundle\ArticleBundle\Metadata\ArticleViewDocumentIdTrait;
+use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector;
+use Sulu\Component\Content\Document\LocalizationState;
use Sulu\Component\Content\Form\Exception\InvalidFormException;
use Sulu\Component\Content\Mapper\ContentMapperInterface;
use Sulu\Component\DocumentManager\DocumentManagerInterface;
@@ -111,6 +113,11 @@ class ArticleController extends AbstractRestController implements ClassResourceI
*/
private $displayTabAll;
+ /**
+ * @var DocumentInspector|null
+ */
+ private $documentInspector;
+
public function __construct(
ViewHandlerInterface $viewHandler,
DocumentManagerInterface $documentManager,
@@ -123,7 +130,8 @@ public function __construct(
RequestHashCheckerInterface $requestHashChecker,
SecurityCheckerInterface $securityChecker,
bool $displayTabAll,
- ?TokenStorageInterface $tokenStorage = null
+ ?TokenStorageInterface $tokenStorage = null,
+ ?DocumentInspector $documentInspector = null
) {
parent::__construct($viewHandler, $tokenStorage);
@@ -137,6 +145,11 @@ public function __construct(
$this->requestHashChecker = $requestHashChecker;
$this->securityChecker = $securityChecker;
$this->displayTabAll = $displayTabAll;
+ $this->documentInspector = $documentInspector;
+
+ if (null === $this->documentInspector) {
+ @trigger_deprecation('sulu/article-bundle', '2.5', 'Instantiating the ArticleController without the $documentInspector argument is deprecated!');
+ }
}
/**
@@ -413,11 +426,27 @@ private function getRangeQuery(string $field, string $from, string $to): RangeQu
public function getAction(Request $request, string $id): Response
{
$locale = $this->getRequestParameter($request, 'locale', true);
+ /** @var ArticleDocument $document */
$document = $this->documentManager->find(
$id,
$locale
);
+ if ($this->documentInspector) {
+ $localizationState = $this->documentInspector->getLocalizationState($document);
+
+ if (LocalizationState::GHOST === $localizationState) {
+ $document = $this->documentManager->find(
+ $id,
+ $locale,
+ [
+ 'load_ghost_content' => false,
+ 'structure_type' => $document->getStructureType(),
+ ]
+ );
+ }
+ }
+
$context = new Context();
$context->setSerializeNull(true);
$context->setGroups(['defaultPage', 'defaultArticle', 'smallArticlePage']);
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
index e07a758b..959dce0f 100644
--- a/Resources/config/services.xml
+++ b/Resources/config/services.xml
@@ -56,6 +56,7 @@