Skip to content

Commit

Permalink
Joomla: Move theme language detection to happen onAfterDispatch where…
Browse files Browse the repository at this point in the history
… it should be (#2522)
  • Loading branch information
mahagr committed Jul 22, 2019
1 parent 5bf3b3a commit a262c99
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
31 changes: 31 additions & 0 deletions platforms/joomla/plg_system_gantry5/gantry5.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Document\HtmlDocument;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Plugin\CMSPlugin;
Expand Down Expand Up @@ -89,6 +90,17 @@ public function onGantryGlobalConfig(&$global)
$global = $this->params->toArray();
}


/**
* Document gets set during dispatch, we need language and direction.
*/
public function onAfterDispatch()
{
if (class_exists('Gantry\Framework\Gantry')) {
$this->onAfterDispatchSiteAdmin();
}
}

public function onAfterRoute()
{
if ($this->app->isClient('site')) {
Expand Down Expand Up @@ -225,6 +237,25 @@ public function onAjaxParticle()
return ['code' => 200, 'type' => $type, 'id' => $identifier, 'props' => (object) $props, 'html' => $html];
}


/**
* Document gets set during dispatch, we need language and direction.
*/
public function onAfterDispatchSiteAdmin()
{
$gantry = Gantry::instance();
$theme = $gantry['theme'];

/** @var CMSApplication $application */
$application = Factory::getApplication();
$document = $application->getDocument();
if ($document instanceof HtmlDocument) {
$document->setHtml5(true);
}
$theme->language = $document->language;
$theme->direction = $document->direction;
}

/**
* Load Gantry framework before dispatching to the component.
*
Expand Down
11 changes: 4 additions & 7 deletions src/platforms/joomla/classes/Gantry/Framework/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

use Gantry\Component\Theme\AbstractTheme;
use Gantry\Component\Theme\ThemeTrait;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Document\HtmlDocument;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;
Expand Down Expand Up @@ -146,6 +146,7 @@ protected function init()
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];

/** @var CMSApplication $application */
$application = Factory::getApplication();
$language = $application->getLanguage();

Expand All @@ -167,12 +168,8 @@ protected function init()
}
}

$doc = $application->getDocument();
if ($doc instanceof HtmlDocument) {
$doc->setHtml5(true);
}
$this->language = $doc->language;
$this->direction = $doc->direction;
$this->language = 'en-gb';
$this->direction = 'ltr';
$this->url = Uri::root(true) . '/templates/' . $this->name;

PluginHelper::importPlugin('gantry5');
Expand Down

0 comments on commit a262c99

Please sign in to comment.