We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    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.
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 22303 MODX Staff
      • 10,725 Posts
      Why can’t you use empty() ?
        • 3749
        • 24,544 Posts
        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.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 18913
          • 654 Posts
          How about "settype" :

          http://php.net/manual/en/function.settype.php


          Maybe the failure of the conversion could serve as a flag to use the system default???? (Personally, I think it would be inelegant as hell and possibly not foolproof. But any port in a storm, as they say ...)

          Just a thought - never tried using it for anything ...
          Matt
            • 3749
            • 24,544 Posts
            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.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 22303 MODX Staff
              • 10,725 Posts
              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. tongue But seriously, I would create a list xtype for the property with no value, ’0’ and ’1’, no?
                • 3749
                • 24,544 Posts
                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. tongue 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.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: BobRay at Dec 21, 2010, 01:26 AM

                  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. tongue 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.

                  They are not really tinyints -- remember, all settings and properties are stored as strings, so I’m referring to empty string (or ’’), ’1’ and ’0’. Not an actual null.
                    • 3749
                    • 24,544 Posts
                    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.

                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 22303 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?