Skip to content

Commit

Permalink
Single-lang fix. Added plugin option for multi-language
Browse files Browse the repository at this point in the history
  • Loading branch information
daveewbl committed Jan 26, 2023
1 parent 6d536cb commit 854b81e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
41 changes: 25 additions & 16 deletions plugin/src/AlgoliaSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,25 @@ protected function findMenuItem($type, $id, $lang)
);

foreach (LanguageHelper::getContentLanguages() as $language) {

$app = CMSApplication::getInstance('site');

$menu_items = $app->getMenu('site')->getItems([
'component_id',
'language'
], [
\JComponentHelper::getComponent('com_zoo')->id,
$language->lang_code
]) ?: [];
$menu_items = array_merge(
// Multi-lang
$app->getMenu('site')->getItems([
'component_id',
'language'
], [
\JComponentHelper::getComponent('com_zoo')->id,
$language->lang_code
]) ?: [],

// Single-lang "*"
$app->getMenu('site')->getItems([
'component_id',
], [
\JComponentHelper::getComponent('com_zoo')->id,
]) ?: [],
);

/** @var MenuItem $menu_item */
foreach ($menu_items as $menu_item) {
Expand Down Expand Up @@ -726,10 +735,6 @@ private function loadRouterLanguageRules(): void
return;
}

if (!PluginHelper::isEnabled('system', 'languagefilter')) {
return;
}

$this->app = CMSApplication::getInstance('site');
$this->lang_codes = LanguageHelper::getLanguages('lang_code');
$this->default_lang = ComponentHelper::getParams('com_languages')->get('site', 'en-GB');
Expand All @@ -746,10 +751,14 @@ private function loadRouterLanguageRules(): void
'preprocessBuildRule'
], Router::PROCESS_BEFORE);

$router->attachBuildRule([
$this,
'buildRule'
], Router::PROCESS_BEFORE);

if ((bool) (new Registry(PluginHelper::getPlugin('system', 'zooalgolia')->params))->get('prepend_language')) {
$router->attachBuildRule([
$this,
'buildRule'
], Router::PROCESS_BEFORE);
}

$router->attachBuildRule([
$this,
'postprocessSEFBuildRule'
Expand Down
8 changes: 8 additions & 0 deletions plugin/zooalgolia.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
<config>
<fields name="params">
<fieldset name="basic">
<field name="prepend_language"
type="list"
default="0"
label="Prepend Language"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
</fields>
</config>
Expand Down

0 comments on commit 854b81e

Please sign in to comment.