Skip to content

Commit

Permalink
Fix setLanguage, check whether keys are valid languages (renderPageBu…
Browse files Browse the repository at this point in the history
…ilderBlock uses pageData without language data)
  • Loading branch information
HansSchouten authored Apr 8, 2022
1 parent 7db80a4 commit d05a439
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Modules/GrapesJS/PageRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,22 @@ public function __construct(ThemeContract $theme, PageContract $page, $forPageBu
*/
public function setLanguage($language)
{
// if the given language is unknown, default the set language to the first available language
$blockKeysAreLanguages = true;
$supportedLanguages = array_keys($this->pageData['blocks'] ?? []);
if (! in_array($language, $supportedLanguages)) {
$language = $supportedLanguages[0] ?? $language;
// check whether keys are valid languages (renderPageBuilderBlock uses pageData without language data)
foreach ($supportedLanguages as $supportedLanguage) {
if (strlen($supportedLanguage) > 5) {
$blockKeysAreLanguages = false;
break;
}
}
if ($blockKeysAreLanguages) {
if (! in_array($language, $supportedLanguages)) {
$language = $supportedLanguages[0] ?? $language;
}
}

$this->language = $language;
$this->pageBlocksData = $this->getStoredPageBlocksData();
$this->shortcodeParser->setLanguage($language);
Expand Down

0 comments on commit d05a439

Please sign in to comment.