Skip to content
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

JApplicationSite getTemplate returns an incomplete class after a setTemplate #8606

Closed
AndyTheFactory opened this issue Dec 6, 2015 · 5 comments

Comments

@AndyTheFactory
Copy link

Steps to reproduce the issue

$app = JFactory::getApplication();
    $t=$app->getTemplate(true);
    var_dump($t);

results in
object(stdClass)#582 (4) {
* ["id"]=>
string(2) "7"
["home"]=>
string(1) "1"
*
["template"]=>
string(10) "protostar"
["params"]=>
object[....]
}

But after a setTemplate, the same call has a different type of result

$app = JFactory::getApplication();
$app->setTemplate('beez3',null);
    $t=$app->getTemplate(true);

results in
object(stdClass)#865 (2) {
["template"]=>
string(10) "rt_anacron"
["params"]=>
..........
}

The previous bolded properties are missing. This leads for instance to some notices in virtuemart+gantry templates

Expected result

The getTemplate(true) call should always return the same type of class

Actual result

The getTemplate(true) call should returns different

System information (as much as possible)

Joomla 3.4.5

Additional comments

The problem is that
public function setTemplate($template, $styleParams = null)
Sets just some part of the JApplicationSite::template class and does not get the id and home from the #__template_styles

The problem is that you could have more then one records in #__template_styles with the same template name
a quick fix would be to add the missing properties with value null.

@Bakual
Copy link
Contributor

Bakual commented Dec 6, 2015

You identified the issue correctly. setTemplate does set the template without specifying a style.

You could set the style properties to null, or you could just check the presence of the property in your own code instead of just assuming they're always there.
Do you want to make a Pull Request?

@ghost
Copy link

ghost commented Dec 7, 2015

To force the current style in too early requests i'm using something like this:

$actMenu = JFactory::getApplication()->getMenu()->getActive();
if (is_null($actMenu))
{
 $template_style_id = 0;
}
else
{
 $template_style_id = (int) $actMenu->template_style_id;
}
if ($template_style_id > 0)
{
 JTable::addIncludePath(JPATH_ADMINISTRATOR  .  '/components/com_templates/tables');
 $style = JTable::getInstance('Style', 'TemplatesTable');
 $style->load($template_style_id);
 if (!empty($style->template))
 {
  $app->setTemplate($style->template, $style->params);
 }
}

@AndyTheFactory
Copy link
Author

The problem is not getting my code to work :) that is easy. The problem is that there are template providers/frameworks like gantry that rely upon that consistency. I can "patch" them for my websites, but that is not a solution :D

I can make a pull request. The question is if i should go the "simple" route and just initialize the missing properties with null, or if I should try to guess the template_id for the template_name (this would be more rigurous)

@Bakual
Copy link
Contributor

Bakual commented Dec 7, 2015

You can't guess the template_id at all. In this cases, there is no style associated. The template is supposed to load with the parameters given in the call, or with its default values if no parameters are given.

@AndyTheFactory
Copy link
Author

Ok, did it on PR#8611

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants