We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Is there a way to know which resource classes are available? One solution is to do a "SELECT DISTINCT" type of query on the modx_site_content table, but I'm hoping for a solution that shows which classes are available even BEFORE any content has been created.

    Thanks!
      • 3749
      • 24,544 Posts
      Maybe you could grep the class files in core/component with a regex something like '/extends.*modResource.*$/' or do it with the DirWalker class in a snippet.
        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
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        The class key dropdown on the resource settings tab I believe talks to the system/derivatives/getlist processor, maybe you can piggyback of that with $modx->runProcessor. Or look at its source for inspiration, apparently there's a $modx->getDescendants method that will look at $modx->classMap to find out what's available.
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 3749
          • 24,544 Posts
          For the record, I'm now somewhat opposed to creating new class_keys if the custom resource is meant mainly to be used instead of the original. I think it's cleaner in most such cases to extend the original object without modifying the class_key. ClassExtender has been modified to leave the class_key fields alone for both modResource and modUser.

          Of course if you need to query just those custom objects (especially if you have a lot of them), changing the class_key makes more sense.
            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
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            Huh, how can you extend it without creating a new class?
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
              • 9207 ☆ A M B ☆
              • 2,475 Posts
              My understanding of the architecture here is that it follows a single-table-inheritance pattern, so everything in there is a resource, but the class_key defines which class is implementing/extending the base interface/class.

              I suspect the processors must contain the solution somewhere... how else does the right-click menu know which options are available, including CRCs?
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                Quote from: Everettg_99 at Nov 14, 2014, 06:30 AM
                My understanding of the architecture here is that it follows a single-table-inheritance pattern, so everything in there is a resource, but the class_key defines which class is implementing/extending the base interface/class.

                I suspect the processors must contain the solution somewhere... how else does the right-click menu know which options are available, including CRCs?

                It traverses the classMap (which is created when building the model from the schema) for descendants.
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 3749
                  • 24,544 Posts
                  Quote from: markh at Nov 14, 2014, 06:21 AM
                  Huh, how can you extend it without creating a new class?

                  You create a custom table for the extra fields, then make modResource a related object of the custom object (which extends modResource). The class_key is still modDocument.

                  $data = $modx->getObject('resourceData', array('resourcedata_id' => 23));
                  $resource = $data->getOne('Resource');


                  You can no longer do this:

                  $resource->getOne('Data');


                  You can, however, do fast queries on the custom table and use getObjectGraph() on it to query it in combination with the resource fields.

                  $c = $modx->newQuery('resourceData');
                  $c->where(array('Resource.pagetitle' => 'Home'));
                  $resource = $modx->getObjectGraph('resourceData', '{"Resource":{}}', $c);
                  $resources = $modx->getCollectionGraph('resourceData', '{"Resource":{}}', $c);


                  Or for users, get the user, the custom data, and the profile all at once:

                  $c = $modx->newQuery('userData');
                  $c->where(array('User.username' => 'BobRay'));
                  $user = $modx->getObjectGraph('userData', '{"Profile":{},"User":{}}', $c);
                  $users = $modx->getCollectionGraph('userData', '{"Profile":{},"User":{}}', $c);


                  This way, the custom class will work with multiple other custom classes that extend the same object (like Articles), which wouldn't allow you to do $article->getOne('Data').
                    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
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    Right, so you are not actually extending the resource/user there, but just creating a separate table to store stuff. And creating a relation back to the resource for convenience. If you just want to store extra data (without using the resource properties) that makes complete sense.
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 9207 ☆ A M B ☆
                      • 2,475 Posts
                      Anyone know the ins/outs of the modx_class_map table? That seems to look promising, but it does not appear to be populated by any Extras, only used by the core (?). It looks like this table would accomplish *exactly* what I'm hoping for: an accessible way to "register" classes so that add-ons can be aware of them.