? Success

User tests: Successful: Unsuccessful:

avatar dgt41
dgt41
23 Apr 2014

This code never made it from the last platform update to the cms.
By deprecating the expressions on modules, we can remove the eval($str) in 4.0. (or maybe even faster???) This is good for HHVM http://hhvm.com

avatar dgt41 dgt41 - open - 23 Apr 2014
avatar dgt41
dgt41 - comment - 23 Apr 2014

Maybe the PLT can go a little bit more bold here and remove the old code:


for ($i = 0, $n = count($words); $i < $n; $i += 2)
{
    // Odd parts (modules)
    $name = strtolower($words[$i]);
    $words[$i] = ((isset(parent::$_buffer['modules'][$name])) && (parent::$_buffer['modules'][$name] === false))
    ? 0
        : count(JModuleHelper::getModules($name));
}

$str = 'return ' . implode(' ', $words) . ';';

return eval($str);
avatar Bakual
Bakual - comment - 23 Apr 2014

Maybe the PLT can go a little bit more bold here and remove the old code:

Why would we want to create a backward compatibility break on purpose when we can properly deprecate the existing function?

Explanation and Testing

Currently, you can do this in your template:
if ($this->countModules('position-1 or position-2 or position-3')) :
It will return true if either of the positions contains a module. You can also use and or some other operators if you want.
The function to make this work uses eval() and some rather complex code.

The idea of this change is that we would deprecate the possibility to use an expression in countModules() and get rid of the eval().

The thing is that you can do the same almost as easy in the template directly. The above code would then look like this:
if ($this->countModules('position-1') or $this->countModules('position-2') or $this->countModules('position-3')) :

To test this, you can use such an call in your template. If you use an expression, you should see a deprecation message in your log file (if you have deprecation logging enabled). It should still work.
If you don't use an expression, you should not get the message and it should of course also work.

avatar dgt41
dgt41 - comment - 23 Apr 2014

I guess I had to ask and get the obvious answer :)

Thanks @Bakual for the nice and thorough explanation :+1:

avatar zero-24
zero-24 - comment - 24 Apr 2014

@dgt41 i have test this here successfull. After enabling Log deprecated API for the Debug Plugin i have add the following lines to the protostar template index.php

if ($this->countModules('position-7 or position-8'))
{
    //Do nothing
}

Then apply your patch and i will see after reload the FE at the Log Part of the Debug console the Message:
WARNING - deprecated
Using an expression in JDocumentHtml::countModules() is deprecated.

Thanks @Bakual for the instructions i will copy it to the JC itm

avatar roland-d
roland-d - comment - 28 May 2014

So I tested this patch and the JLog::add is triggered but I don't get any log where this is written. Is there anything in particular to set up? I have enabled the Debug system option. The array of loggers is empty, so there is no place to write the log.

Once this goes ahead, this document needs to be updated as well:
http://docs.joomla.org/JDocumentHTML/countModules

avatar dgt41
dgt41 - comment - 28 May 2014
avatar roland-d
roland-d - comment - 11 Jun 2014

@dgt41 Thanks for the hint, now I was able to test it successfully. The JC tracker has been set to RTC.

Only thing left to do is update the documentation.

avatar phproberto phproberto - reference | - 11 Jun 14
avatar phproberto phproberto - close - 11 Jun 2014
avatar phproberto phproberto - change - 11 Jun 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-06-11 23:15:16
avatar phproberto phproberto - close - 11 Jun 2014
avatar dgt41 dgt41 - head_ref_deleted - 12 Jun 2014
avatar zero-24
zero-24 - comment - 21 Jun 2014

Only thing left to do is update the documentation.

@roland-d I have just add a "Warning" message there.

avatar dgt41
dgt41 - comment - 21 Jun 2014

Anyone with credentials maybe can update. I made a doc with all the changes here: https://docs.google.com/document/d/1Csn0FMxLNCpGLU8gpGK2j_QNbWZ6KJ5xE2nEpUI5r60/edit?usp=sharing

avatar roland-d
roland-d - comment - 18 Jul 2014

@dgt41 when you register at the docs.joomla.org website, you should be able to edit or not?

avatar Hutchy68
Hutchy68 - comment - 18 Jul 2014

Thanks for the doc update. :+1:

avatar roland-d
roland-d - comment - 18 Jul 2014

@dgt41 Looks good to me :+1: Thanks for that.

avatar dgt41
dgt41 - comment - 2 Dec 2014

test “test” ‘test’ test

Add a Comment

Login with GitHub to post a comment