Page 1 of 1
zeros not shown in admin content field [SOLVED]
Posted: Wed Aug 11, 2010 12:43 pm
by palun
Single zeros ('0') in content seem to disappear from admin page when the page is refreshed.
Try this:
-- In the content box of an admin-page, write a single zero (witout any formatting)
-- Save the page
-- Reopen (or refresh) the page - the zero is gone!
The corresponding published page looks ok though - it shows the '0' where it's supposed to be.
The above only applies to single zeros. Versions such as '0.0', '00' or '0' work as expected.
Unfortunately, custom content fields behave the same way, and this is really the reson I'm posting -- I have custom fields that should accept integers, including '0'.
Any ideas on how to fix/workaround this?
/ulf
PS. If this is a known pre-1.8 problem, I apologize. I'm still running 1.7.1. (Will update as soon as time allows.)
Re: zeros not shown in admin content field
Posted: Thu Aug 12, 2010 8:18 pm
by palun
It's awfully quiet...
Am I missing something obvious here?
/ulf
Re: zeros not shown in admin content field
Posted: Fri Aug 13, 2010 5:12 pm
by NaN
Not sure but i believe the is an issue in the content type.
I just looked in the SVN rev 6471 of 1.8.x branch and in lib/classes/contenttypes/Content.inc.php it says:
// add content blocks.
foreach($this->_contentBlocks as $blockName => $blockInfo)
{
$data = $this->GetPropertyValue($blockInfo['id']);
if( empty($data) && isset($blockInfo['default']) ) $data = $blockInfo['default'];
$tmp = $this->display_content_block($blockName,$blockInfo,$data,$adding);
if( !$tmp ) continue;
$ret[] = $tmp;
}
1st: isset($blockInfo['default']) makes not sense to me since it is always set (when parsing the template for the content blocks it always is set - regardless if it contains any value)
2nd: empty($data) ... if the var $data conatins a single zero the php function emty() will return true.
And this means if the content contains a single zero it will be set to the default content.
If no default content is used the content will be set to an empty value.
So the code above should be at least this way:
// add content blocks.
foreach($this->_contentBlocks as $blockName => $blockInfo)
{
$data = $this->GetPropertyValue($blockInfo['id']);
if( $data=='' && isset($blockInfo['default']) ) $data = $blockInfo['default'];
$tmp = $this->display_content_block($blockName,$blockInfo,$data,$adding);
if( !$tmp ) continue;
$ret[] = $tmp;
}
(sorry, i have no editor here to get the line numbers. but i believe one of the devs will know what i'm talking about)
Re: zeros not shown in admin content field
Posted: Fri Aug 13, 2010 5:50 pm
by Dr.CSS
It is true, content block with a single 0 in it will get emptied, but why would someone put only a single 0 in a content block...
Re: zeros not shown in admin content field
Posted: Fri Aug 13, 2010 6:41 pm
by JeremyBASS
for what it's worth it's think that the switch like NaN showed would be good.. I'd think
if( $data==''
would be cheaper then
if( empty($data)
and then solve this "issue" not that I think it is imho.. Just My2Cents

Re: zeros not shown in admin content field
Posted: Fri Aug 13, 2010 7:47 pm
by NaN
Dr.CSS wrote:
but why would someone put only a single 0 in a content block...
IMHO this should be the users choice.
If i enter exactly just one single zero, i just want exactly one single zero.
That's all.
But the more important point is that in this case if i reload the edit panel the value of the param default will be used even if i enter something in the content.
So if i click submit the zero is even gone in frontend.
Just an example:
{content block="show_news" label="Show news in sidebar?" assign="show_news" oneline=true default=1}
{if $show_news}
{news}
{/if}
When editing the page the first time i can enter a single zero.
So the news will be hidden.
Whenever i edit the content again without touching that block... yeah! The news suddenly will be shown since the default value is taken
In this case zero just means zero.
And not "nothing" and not even "default value".
So i think this should be fixed.
Re: zeros not shown in admin content field
Posted: Fri Aug 13, 2010 7:51 pm
by JeremyBASS
agreed +1 to fix
Re: zeros not shown in admin content field
Posted: Fri Aug 13, 2010 8:26 pm
by palun
Thank you all for clarifying this!
Regarding the reason for wanting single zeros:
In my case, web pages represent objects that have attributes, some of which are not displayed but used in computations in the background, or they are displayed indirectly. I am, for instance, using integers for the coordinates of a standard (fixed) diagram curve. I simply added these fields as custom content blocks (hiding them using CSS). That way the customer gets easy access to the data in the CMSMS admin panel and is free to edit them there. I thought that was a really elegant solution... (The alternative would have been hardcoding the values.)
I would love to see this fixed in a future version. Meantime I'll give it a try myself. (Although I'm no PHP programmer...)
Thanks again!
/ulf
Re: zeros not shown in admin content field
Posted: Fri Aug 13, 2010 11:34 pm
by palun
I did as NaN suggested and now it works fine! (In v 1.7.1, it's line 179 in Content.inc.php.)
Thanks!
/ulf