Skip to content

Commit

Permalink
FIX Don't try to preview unlocalised objects
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Mar 2, 2023
1 parent 79a1568 commit 975329b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/Extension/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,22 @@ public function updateFluentCMSField(FormField $field)
$field->setTitle($tooltip);
}

/**
* Update preview link to null if the object isn't in the current locale
* and we can't fallback cleanly.
*
* @param ?string $link
*/
public function updatePreviewLink(&$link): void
{
$owner = $this->owner;
$info = $owner->LocaleInformation(FluentState::singleton()->getLocale());

if (!$info->getSourceLocale()) {
$link = null;
}
}

/**
* Require that this record is saved in the given locale for it to be visible
*
Expand Down
5 changes: 0 additions & 5 deletions src/Middleware/InitStateMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ public function getIsFrontend(HTTPRequest $request)
}
}

// If using the CMS preview, do not treat the site as frontend
if ($request->getVar('CMSPreview')) {
return false;
}

return true;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/php/Middleware/InitStateMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function isFrontendProvider()
['/', [], true],
['foo', [], true],
['my-blog/my-post', [], true],
['my-blog/my-post', ['CMSPreview' => 1], false],
// CMS preview is front-end, and if there's no localised copy the PreviewLink will be null
['my-blog/my-post', ['CMSPreview' => 1], true],
];
}
}

0 comments on commit 975329b

Please sign in to comment.