-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jroute between sites #16879
Jroute between sites #16879
Changes from 15 commits
69f4f3f
d8e7a5d
9c1a3a8
7933bdb
173c231
0faa289
2ad9ffd
0f1d95b
4502d6f
d07ee16
3ef9ba2
a4eaa94
219438b
129d14c
671b504
94bdfc5
c7dd17d
1b233d5
0686d07
eb26908
0b5ad2e
12633a3
fadc304
a783d23
fdfa09b
5bf6b0a
1d79429
300699d
124aab1
b3136c4
a91cd6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,14 +91,15 @@ public function __construct(&$subject, $config) | |
|
||
$this->app = JFactory::getApplication(); | ||
|
||
// Setup language data. | ||
$this->mode_sef = $this->app->get('sef', 0); | ||
$this->sefs = JLanguageHelper::getLanguages('sef'); | ||
$this->lang_codes = JLanguageHelper::getLanguages('lang_code'); | ||
$this->default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB'); | ||
|
||
// If language filter plugin is executed in a site page. | ||
if ($this->app->isClient('site')) | ||
{ | ||
// Setup language data. | ||
$this->mode_sef = $this->app->get('sef', 0); | ||
$this->sefs = JLanguageHelper::getLanguages('sef'); | ||
$this->lang_codes = JLanguageHelper::getLanguages('lang_code'); | ||
$this->default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB'); | ||
|
||
$levels = JFactory::getUser()->getAuthorisedViewLevels(); | ||
|
||
foreach ($this->sefs as $sef => $language) | ||
|
@@ -112,6 +113,21 @@ public function __construct(&$subject, $config) | |
} | ||
} | ||
} | ||
// If language filter plugin is executed in a admin page (ex: JRoute site). | ||
else | ||
{ | ||
// Set current language to default site language, fallback to en-GB if there is no content language for the default site language. | ||
$this->current_lang = isset($this->lang_codes[$this->default_lang]) ? $this->default_lang : 'en-GB'; | ||
|
||
foreach ($this->sefs as $sef => $language) | ||
{ | ||
if (!array_key_exists($language->lang_code, JLanguageHelper::getInstalledLanguages(0))) | ||
{ | ||
unset($this->lang_codes[$language->lang_code]); | ||
unset($this->sefs[$language->sef]); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -125,26 +141,24 @@ public function onAfterInitialise() | |
{ | ||
$this->app->item_associations = $this->params->get('item_associations', 0); | ||
|
||
if ($this->app->isClient('site')) | ||
{ | ||
$router = $this->app->getRouter(); | ||
|
||
// Attach build rules for language SEF. | ||
$router->attachBuildRule(array($this, 'preprocessBuildRule'), JRouter::PROCESS_BEFORE); | ||
$router->attachBuildRule(array($this, 'buildRule'), JRouter::PROCESS_DURING); | ||
// We need to make sure we are always using the site router, even if the language plugin is executed in admin app. | ||
$router = $this->app->isClient('site') ? $this->app->getRouter() : JApplicationCms::getInstance('site')->getRouter('site'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just have this always call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. |
||
|
||
if ($this->mode_sef) | ||
{ | ||
$router->attachBuildRule(array($this, 'postprocessSEFBuildRule'), JRouter::PROCESS_AFTER); | ||
} | ||
else | ||
{ | ||
$router->attachBuildRule(array($this, 'postprocessNonSEFBuildRule'), JRouter::PROCESS_AFTER); | ||
} | ||
// Attach build rules for language SEF. | ||
$router->attachBuildRule(array($this, 'preprocessBuildRule'), JRouter::PROCESS_BEFORE); | ||
$router->attachBuildRule(array($this, 'buildRule'), JRouter::PROCESS_DURING); | ||
|
||
// Attach parse rules for language SEF. | ||
$router->attachParseRule(array($this, 'parseRule'), JRouter::PROCESS_DURING); | ||
if ($this->mode_sef) | ||
{ | ||
$router->attachBuildRule(array($this, 'postprocessSEFBuildRule'), JRouter::PROCESS_AFTER); | ||
} | ||
else | ||
{ | ||
$router->attachBuildRule(array($this, 'postprocessNonSEFBuildRule'), JRouter::PROCESS_AFTER); | ||
} | ||
|
||
// Attach parse rules for language SEF. | ||
$router->attachParseRule(array($this, 'parseRule'), JRouter::PROCESS_DURING); | ||
} | ||
|
||
/** | ||
|
@@ -157,7 +171,7 @@ public function onAfterInitialise() | |
public function onAfterRoute() | ||
{ | ||
// Add custom site name. | ||
if (isset($this->lang_codes[$this->current_lang]) && $this->lang_codes[$this->current_lang]->sitename) | ||
if ($this->app->isClient('site') && isset($this->lang_codes[$this->current_lang]) && $this->lang_codes[$this->current_lang]->sitename) | ||
{ | ||
$this->app->set('sitename', $this->lang_codes[$this->current_lang]->sitename); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a
trigger_error()
call because you in essence have a "call to undefined function" error here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we check for a valid client name here, the behavior would be different when called using undescore function. That function fails silently on invalid router and we need to keep it like that for B/C, imho.
And here we are only checking for missing first parameter coz we need to populate 4th parameter.
Another alternate way that comes to my mind is to not modify the undescore function signature and add another common function that accepts client name as first parameter.
We might then not need the magic function too. Your opinion please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I hate the use of magic functions. They usually expose unwanted behavior and do not handle error conditions appropriately (in an error state they should do the same thing as the native PHP engine does for whatever that magic function is overloading). Even in the Framework's database repo, I removed
__call()
and just made "real" stub methods for the shorthandq()
,qn()
, ande()
methods.So personally I'd just add stub real methods and avoid the magic as a first option. If the magic method is really needed, then it needs to error trap/handle properly.
If the system can't generate a route, it shouldn't silently fail over. There needs to be an error raised.