goldsky / GridClassKey

A custom class key for MODX Revolution's Manager to hide child resources inside container's grid.
8 stars 7 forks source link

Output filter for published [$5 awarded] #129

Closed vierkantemeter closed 9 years ago

vierkantemeter commented 9 years ago

I'm trying to use an output filter for the published column, like this:

if ($input == true) { return 'yes'; } else { return 'no'; } return '';

I named it 'gckpublished' and I added it to the column 'output filter' like this: :gckpublished

What happens is that I do see 'yes' and 'no' correct in the published column, but it's like the resource is always published for GCK: the action icon and context menu are wrong ('unpublish' when the resource was already unpublished) and the resource is not displayed in italics. So it looks like it's published, but it's not.

What could be wrong? I also tried with 1 instead of true, and with quotes. Same result.

What could be the problem?

--- The **[$5 bounty](https://www.bountysource.com/issues/9516865-output-filter-for-published?utm_campaign=plugin&utm_content=tracker%2F570466&utm_medium=issues&utm_source=github)** on this issue has been claimed at [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F570466&utm_medium=issues&utm_source=github).
goldsky commented 9 years ago

Modx version?

vierkantemeter commented 9 years ago

Sorry, forgot to mention.

MODX 2.3.3 GCK 1.0.1 rc3

goldsky commented 9 years ago

Ow, sorry, I didn't realize you've chip in?

goldsky commented 9 years ago

this works, notice the string 'true'

<?php

if ($input == 'true') {
    return 'yes';
} else {
    return 'no';
}
return '';
vierkantemeter commented 9 years ago

Hi Goldsky, unfortunately that's also not working for me. Same result... If you want I can give you a login to have a look.

goldsky commented 9 years ago

sure, goldsky@virtudraft.com please

vierkantemeter commented 9 years ago

Thanks! I emailed you the details.

vierkantemeter commented 9 years ago

Did you find anything?

(For any other readers; goldsky looked at my install, and it's a bug)

goldsky commented 9 years ago

I thought I've answered your email, and you understood by saying 'OK' :)

I believe, the output filter for the published overrides the expected value for the grid to render the output. It expects boolean result, while the output filter overrides it to "no" or "yes" string. Once you remove the output filter, all the related functions, like: icon, style, and right-click menu, should work back. The work around is by creating another snippet that gets that "published" value, and add that snippet into the GCK's column.

But nevermind, I've make the snippet, gckpublished becomes the field, not the output filter.

vierkantemeter commented 9 years ago

Thanks, didn't get that email! But I just checked the site again and everything works. Thank you! Could you explain how the gckpublished snippet gets the published value? Is this by default available in $scriptProperties['published'] ?

goldsky commented 9 years ago

For each row, yes. You can uncomment the logging line, and check the error log.

vierkantemeter commented 9 years ago

Alright, thanks!

For anyone interested, here is the snippet code. Add this as snippet field in GCK.

<?php
//$modx->log(modX::LOG_LEVEL_ERROR, __LINE__ . ': $scriptProperties ' . print_r($scriptProperties, 1));
if ($scriptProperties['published'] == '1') {
    return 'Published';
} else {
    return 'Unpublished';
}
return '';