modxcms / revolution

MODX Revolution - Content Management Framework
https://modx.com/
GNU General Public License v2.0
1.36k stars 529 forks source link

Default value bindings fails when empty or 0 with @EVAL #13548

Closed sdrenth closed 6 years ago

sdrenth commented 7 years ago

Summary

The issue has to do with this pull request: https://github.com/modxcms/revolution/pull/13378

I manually edited the changed file from the PR above into a 2.5.6 MODX website, because I needed to have a dynamic default TV value.

Step to reproduce

Add select TV, add three options: Default==0||Option 1==1||Option 2==2

Add this code in the default value field: @EVAL return $modx->runSnippet('defaultTVValue');

Create snippet defaultTVValue:

$context = $_GET['context_key'] ? $_GET['context_key'] : 'web';

$tvValue = 0;
switch ($context) {
    case 'context-1':
        $tvValue = 1;
        break;
    case 'context-2':
    case 'context-3':
        $tvValue = 2;
        break;
}

return $tvValue;

Observed behavior

When creating a resource in the WEB context the following default input value is shown in the TV: @EVAL return $modx->runSnippet('getDefaultBrandsValue');

If i create a resource in another context, so the default TV value is not 0, then the default TV option is set correctly.

This also happens when I set the default TV value to an empty string, so $tvValue = '';

Expected behavior

I expect the TV to show the option Default as default input value when I create a resource for context web.

Environment

rtripault commented 7 years ago

Confirming the issue here.

FWIW, TVs always had issues with handling integers (especially "0").

If you change your TV values to be strings, the issue is no more (quick workaround tho, no real fix)

alroniks commented 6 years ago

Closing as wontfix because in 3.x @EVAL binding was removed by security reasons. See https://github.com/modxcms/revolution/pull/13865/files