public function setTheme($theme, $style) { if ($style) { \JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables'); $table = \JTable::getInstance('Style', 'TemplatesTable'); $table->load(['id' => $style, 'client_id' => 0]); $theme = $table->template; } if (!$theme) { $theme = StyleHelper::getDefaultStyle()->template; } $path = JPATH_SITE . '/templates/' . $theme; if (!is_file("{$path}/gantry/theme.yaml")) { $theme = null; $this->container['streams']->register(); /** @var UniformResourceLocator $locator */ $locator = $this->container['locator']; $this->container['file.yaml.cache.path'] = $locator->findResource('gantry-cache://theme/compiled/yaml', true, true); } $this->container['base_url'] = \JUri::base(true) . '/index.php?option=com_gantry5'; $this->container['ajax_suffix'] = '&format=json'; $token = \JSession::getFormToken(); $this->container['routes'] = ['1' => "&view=%s&theme={$theme}&{$token}=1", 'themes' => '&view=themes', 'picker/layouts' => "&view=layouts&theme={$theme}&{$token}=1"]; if (!$theme) { return $this; } $this->container['theme.path'] = $path; $this->container['theme.name'] = $theme; // Load language file for the template. $languageFile = 'tpl_' . $theme; $lang = \JFactory::getLanguage(); $lang->load($languageFile, JPATH_SITE) || $lang->load($languageFile, $path) || $lang->load($languageFile, $path, 'en-GB'); return $this; }
protected function getInput() { $app = JFactory::getApplication(); // Detect Gantry Framework or fail gracefully. if (!class_exists('Gantry5\\Loader')) { $app->enqueueMessage(JText::sprintf('MOD_GANTRY5_PLUGIN_MISSING', JText::_('MOD_GANTRY5_PARTICLE')), 'error'); return ''; } if (!defined('GANTRYADMIN_PATH')) { define('GANTRYADMIN_PATH', JPATH_ADMINISTRATOR . '/components/com_gantry5'); } // Initialize administrator or fail gracefully. try { Gantry5\Loader::setup(); $this->container = Gantry\Framework\Gantry::instance(); $this->container['router'] = function ($c) { return new \Gantry\Admin\Router($c); }; } catch (Exception $e) { $app->enqueueMessage(JText::sprintf($e->getMessage()), 'error'); return ''; } // FIXME: Use better style detection (via js by using: style_id_field). $style = \Gantry\Joomla\StyleHelper::getStyle(['home' => 1, 'client_id' => 0]); $theme = \Gantry\Joomla\StyleHelper::getDefaultStyle()->template; $this->container['router']->setTheme($theme, $style->id)->load(); $field = ['default' => true, 'scope' => '', 'name' => $this->name, 'field' => ['type' => 'gantry.particle', 'label' => 'Particle', 'class' => 'input-small', 'picker_label' => 'Pick a Particle', 'overridable' => false], 'value' => json_decode($this->value, true)]; $params = ['content' => $this->container['admin.theme']->render('@gantry-admin/forms/fields/gantry/particle.html.twig', $field)]; return $this->container['admin.theme']->render('@gantry-admin/partials/layout.html.twig', $params); }
public function setStyle($style) { $style = $style ? $style : StyleHelper::getDefaultStyle()->id; if ($style) { \JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables'); $table = \JTable::getInstance('Style', 'TemplatesTable'); $table->load(['id' => $style, 'client_id' => 0]); $template = $table->template; $path = JPATH_SITE . '/templates/' . $template; $this->container['theme.path'] = $path; $this->container['theme.name'] = $template; // Load language file for the template. $languageFile = 'tpl_' . $template; $lang = \JFactory::getLanguage(); $lang->load($languageFile, JPATH_SITE) || $lang->load($languageFile, $path) || $lang->load($languageFile, $path, 'en-GB'); } $this->container['base_url'] = \JUri::base(true) . '/index.php?option=com_gantry5'; $this->container['ajax_suffix'] = '&format=json'; $token = \JSession::getFormToken(); $this->container['routes'] = ['1' => "&view=%s&style={$style}&{$token}=1", 'themes' => '&view=themes', 'picker/layouts' => "&view=layouts&style={$style}&{$token}=1"]; return $this; }