I can’t seem to find any resolution to this problem.
I’m working on NewsPublisher and need to deal with isfolder, published, cacheable, and searchable.
1. I want to include these boolean properties in the default properties of the snippet so users will know they are there and see their descriptions.
2. In my code, I’d like to use the default System Settings for them if the user has not set a value.
It seems like a common thing to want to do, but as far as I can tell, it’s impossible.
If a boolean default property exists, it is set, so I can’t use isset(); and since it is a boolean, I can’t use empty(), nor can I use === because it is always set to one of the two values.
The only solutions I can think of are to leave them out of the default properties or to set them and ignore the system defaults. I hate to do either one. I could make them text fields, but then the user can enter meaningless values in the properties (e.g., ’oui’), and in the code I can’t tell they are boolean any more so, I’d have to check all the field names to generate checkboxes for them in the form.
The only alternative I can think of is to create a third option (’Not Set’) in the Yes/No property value drop-down and set some other value (3, 127, null ... etc.) for it in the DB.
Hopefully, there’s something I’m not seeing here. It’s the first thing in MODx that I’ve ever wanted to do that’s impossible.
-
MODX Staff
- 10,725 Posts
Why can’t you use empty() ?
I want to distinguish 3 conditions: true, false, and not set. I only want to use the system default setting if it’s not set, but I don’t think empty() will distinguish between false and not set.
If a boolean default property exists, it is in the $scriptProperties array as "0" or "1". IOW, there’s no way for the user *not* to set it.
Quote from: OpenGeek at Dec 20, 2010, 11:54 PM
Quote from: BobRay at Dec 20, 2010, 09:56 PM
If a boolean default property exists, it is in the $scriptProperties array as "0" or "1". IOW, there’s no way for the user *not* to set it.
It’s boolean though, that’s not really valid; consider it not allowing nulls.
But seriously, I would create a list xtype for the property with no value, ’0’ and ’1’, no?
Right, if they accepted null or some other value, (since their really tinyints), null could represent unset.
I’ll play with the list type.
Duh. I was confusing them with the resource fields of the same name. Unlike the resource fields, it looks like the properties are stored as as an empty string if they are created without being set and converted to JSON boolean true or false if they’re ever marked as dirty. I think that could work. I assume that the true or false are converted to ’0’ and ’1’ on the way out. Is that right?
BTW, the trouble with using a list type is that then there’s no generic way to tell which properties are boolean so they can be rendered as checkboxes in a form. I my specific case, I could test the resource fields of the same name for that. I may end up doing it that way. I like the idea of providing a list with System Default, Parent, Yes, and No, as options.
-
MODX Staff
- 10,725 Posts
Don’t make them xtype boolean; they need to be a list. This is a 3-way list; three options, not two. The property is simply an option of none, Yes or No with values of ’’, ’1’, and ’0’ corresponding, no?