Skip to content

Commit

Permalink
Fix return value for getConfiguredLanguages method that would cause an
Browse files Browse the repository at this point in the history
exception in some instances. Fluency now boots the translation engine
outside of the admin in case $fluency is used outside of the admin. Fix
link rendering issue. Update CHANGELOG.md
  • Loading branch information
SkyLundy committed Dec 22, 2023
1 parent 3aae420 commit ad9a511
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Fluency for ProcessWire Changelog

## 1.0.5 2023-12-22

### _Critical update_, Bugfix upgrade recommended for all users.

- Fix return type error when Fluency attempts to get configured languages in some instances credit
to @jacmaes for finding and reporting. Closes [issue 3](https://github.com/SkyLundy/Fluency/issues/3).
- Fix bug where rendering langauge links appended an extra divider after list if a divider was
passed to the method

## 1.0.4 2023-12-19

### Enhancement, Documentation
Expand Down
2 changes: 1 addition & 1 deletion Fluency.info.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$info = [
'title' => 'Fluency',
'version' => '103',
'version' => '105',
'href' => 'https://processwire.com/talk/topic/24567-fluency-integrated-deepl-powered-content-translation',
'icon' => 'language',
'summary' => 'The complete translation enhancement suite for ProcessWire.',
Expand Down
25 changes: 12 additions & 13 deletions Fluency.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ public function ready() {
$this->fluencyConfig = (new FluencyConfig())->getConfigData();
$this->translationCache = new TranslationCache();
$this->engineLanguagesCache = new EngineLanguagesCache();
$this->initializeTranslationEngine();

if (!$this->moduleShouldInit()) {
if (!$this->moduleShouldInitInAdmin()) {
return false;
}

$this->initializeTranslationEngine();
$this->insertPageAssets();
$this->insertAdminAssets();
}

/**
* Determine if module should initialize
*/
private function moduleShouldInit(): bool {
private function moduleShouldInitInAdmin(): bool {
return $this->page->name !== 'login' && $this->userIsAuthorized();
}

Expand Down Expand Up @@ -159,7 +159,7 @@ private function userIsAuthorized(): bool {
/**
* Inserts required assets into admin pages on load.
*/
private function insertPageAssets(): void {
private function insertAdminAssets(): void {
if ($this->page->rootParent->id !== 2 ) {
return;
}
Expand Down Expand Up @@ -286,7 +286,9 @@ public function getConfiguredLanguages(): AllConfiguredLanguagesData {
$engineInfo = $this->translationEngineInfo;

if (!$engineInfo?->configId) {
return [];
return AllConfiguredLanguagesData::fromArray([
'languages' => []
]);
}

if (!is_null($this->configuredLanguages)) {
Expand All @@ -308,11 +310,7 @@ public function getConfiguredLanguages(): AllConfiguredLanguagesData {

$processWireLanguages = array_values($this->languages->getIterator()->getArray());

$languages = array_reduce(
$processWireLanguages,
$createConfiguredLanguage,
[]
);
$languages = array_reduce($processWireLanguages, $createConfiguredLanguage, []);

// Create an array of Fluency configured language object from an array of ProcessWire languages
return $this->configuredLanguages = AllConfiguredLanguagesData::fromArray([
Expand Down Expand Up @@ -411,7 +409,7 @@ public function getUnconfiguredLanguages(): array {
*
* #pw-group-Fluency-Module-Configuration-Data
*
* @return array Array with all data needed by client UI scripts.
* @return stdClass All data needed by client UI scripts.
*/
public function getClientData(): stdClass {
return (object) [
Expand Down Expand Up @@ -587,6 +585,7 @@ public function renderLanguageLinks(
string $languageSource = 'fluency',
): string {
$languages = $this->getLanguagesForMarkup($languageSource);
$divider && $divider = Markup::li(content: $divider, classes: 'divider');

$items = array_reduce($languages, function($tags, $language) use ($activeClass, $divider) {
$tags[] = Markup::li(
Expand All @@ -597,7 +596,7 @@ classes: $language->isCurrentLanguage ? $activeClass : null,
)
);

$divider && $tags[] = Markup::li(content: $divider, classes: 'divider');
$divider && $tags[] = $divider;

return $tags;
}, []);
Expand Down

0 comments on commit ad9a511

Please sign in to comment.