We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I'm following along with the documentation about creating custom resource classes, specifically these pages:


    I can't get this to work... wondering if anyone could point me in the right direction. I've tried going through the steps verbatim and in variations, but I still see no results. Specifically here are my questions:

    1. When creating the XML schema file, where should that file be saved and what naming conventions must it follow?
    2. Inside the XML schema file, what must be the names of the package and the object be? Does case matter?
    3. Where should the maps and class files end up? What is the logic of the structure here? It seems redundant to have smurf/model/smurf etc.
    4. Is the addExtensionPackage method supposed to modify the extension_packages System Setting? Is there a benefit for editing the System Setting directly? And again, what's the naming convention there?

    Thanks for any pointers.
    • I'm just starting create custom resource class. But instead of using the tutorial in rtfm, I use Article extra as template (https://github.com/splittingred/Articles).

      Not finish yet. But seem all works fine till now. [ed. note: lokamaya last edited this post 11 years, 4 months ago.]
        zaenal.lokamaya
      • Assuming I create a new extra "MyExtra", there should be some directories inside MyExtra:

        +MyExtra
         + _build
         + assets
         + core
           + components
             + myextra
               + docs
               + elements
               + model
                 + myextra // default directory for main package (schema)
                   + mysql // if we provide mysql schema
                   + mssql // if we provide mssql schema
                 + anotherpackagename // another directory for additional package (schema)
                   + mysql 
                   + mssql 
                 + schema
                   - myextra.mysql.schema.xml
                   - myextra.mssql.schema.xml
                   - anotherpackagename.mysql.schema.xml
                   - anotherpackagename.mssql.schema.xml
        


        Quote from: Everettg_99 at Dec 12, 2012, 09:48 PM

        1. When creating the XML schema file, where should that file be saved and what naming conventions must it follow?

        The file must be saved inside path/to/MyExtra/core/components/myextra/model/schema/. There is no naming convention for filename, as long as it reflect the packageName in our shcema.

        For example, the packageName "myextra" for MySQL should be saved as myextra.mysql.schema.xml:
        <model package="myextra" version="1.0.0" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">


        It's possible to have more than one schema in our extra, and each schema (packageName) will have it's own directory inside "model/" directory.

        Quote from: Everettg_99 at Dec 12, 2012, 09:48 PM

        2. Inside the XML schema file, what must be the names of the package and the object be? Does case matter?

        The case matter. The packageName is better using all lowercase "myextra". But there are no naming convention for objectName. Below some example:

        <model package="myextra" version="1.0.0" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
            <object class="AnyObjectName" extends="modResource">
                <composite alias="Children" class="OtherObjectName" local="id" foreign="parent" cardinality="many" owner="local" />
            </object>
            <object class="OtherObjectName" extends="modResource">
                <aggregate alias="ParentDir" class="AnyObjectName" local="parent" foreign="id" cardinality="one" owner="foreign" />
                <alias key="sku" field="menutitle" />
                <alias key="images" field="introtext" />
            </object>
        </model>


        Quote from: Everettg_99 at Dec 12, 2012, 09:48 PM

        3. Where should the maps and class files end up? What is the logic of the structure here? It seems redundant to have smurf/model/smurf etc.

        As mentioned above, the directory name for maps and xpdoObjectClass depend on packageName in our schema.

        Then there will be database specific xpdoAbstractionLayerClass for our schema, and it will be saved in sub-directory "mysql" or "mssql" regarding the database we use.

        If there are more than one schema, i.e. anotherpackagename.mysql.schema.xml, it should be ended up in path/to/MyExtra/core/components/myextra/model/anotherpackagename/.

        Quote from: Everettg_99 at Dec 12, 2012, 09:48 PM

        4. Is the addExtensionPackage method supposed to modify the extension_packages System Setting? Is there a benefit for editing the System Setting directly? And again, what's the naming convention there?

        I guess there is no naming convention here. But previously when I try to create myextra_mysystemsetting1, myextra_mysystemsetting2 ... myextra_mysystemsettingN, it produces weird behavior when accessing System Setting page. The System Setting grid only showing 5 records even if I have more than 35 records and I can not get more then 1 page. (i don't know it's a feature or a bug).

        So it's safe to create system setting using following format: myextra.mysystemsetting (using "dot" not "underscore"). [ed. note: lokamaya last edited this post 11 years, 4 months ago.]
          zaenal.lokamaya
        • (1) Where the schema needs to go: doesn't matter. As long as your map/model build script knows where it is. It's usually either in _build/schema/, but putting it in core/components/myextra/schema/ enables developers using your tool to check out the XML schema without having to find the source on github.

          (2) As lokomaya said; it's recommended to keep the packagename lowercase. The objects itself is up to you, but I personally prefer camelCase, prefixed with an abbreviation for the package name. Like myextSomeObject.

          (3) The map and base classes should automatically be generated in the directory you identified. May sound redundant, until you hit the scenario lokamaya sketched with different packages in one.

          (4) Yes, that method is supposed to update that setting. It's best to use that in case in the future extension packages are handled differently than the setting; using addExtensionPackage would still work but directly toying might not.


          Generally, your packagename === namespace === extension_packages key value === core/components directory etc.
            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.
            • 10378
            • 375 Posts
            Quote from: lokamaya at Dec 23, 2012, 04:29 PM
            I'm just starting create custom resource class. But instead of using the tutorial in rtfm, I use Article extra as template (https://github.com/splittingred/Articles).

            Not finish yet. But seem all works fine till now.

            Hi lokamaya,

            I currently try to do the same: Creating my own container/child-resource based custom resource type! I also tried to use the Articles extra as a reference / development boilerplate. What I try to do is, removing all blog based features from Articles package (comments, tags, notifications, archives, ...) and create a "simple" and universal content type to handle all kind of resources which I don't want to manage through the MODx resource tree.

            What exactly did you try to achieve?
            How far did you come with your work?

            Greetings,
            Martin
              Freelancer @bitego http://www.bitego.com
              ---
              GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
              More infos here: http://www.bitego.com/extras/goodnews/
              • Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 10378
                • 375 Posts
                Quote from: sottwell at May 05, 2013, 10:24 AM
                You could use MIGXdb... http://rtfm.modx.com/display/ADDON/MIGXdb.Manage+Child-Resources+in+a+grid-TV+with+help+of+MIGXdb

                Hi Susan,

                thanks for your hint, but I can't use MIGXdb as we need a special custom resource type for our current project with some extra fields and behavior and also a custom resource container like in Articles plugin. It's simply too specific and we also need some integration in the CMP of our project.

                Greetings,
                Martin
                  Freelancer @bitego http://www.bitego.com
                  ---
                  GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                  More infos here: http://www.bitego.com/extras/goodnews/
                • Anyone know how I can customize the "New Document" text that appears when I'm creating a new blog entry or new (insert CRC here)?

                  http://www.screencast.com/t/5ahzh3AR72C
                  • That would be in your lexicon; the default is found in core/lexicon/<lang>/resource.inc.php

                    http://rtfm.modx.com/display/revolution20/Creating+a+Resource+Class
                    public function getContextMenuText() {
                      $this->xpdo->lexicon->load('copyrightedresource:default');
                      return array(
                        'text_create' => $this->xpdo->lexicon('copyrightedresource'),
                        'text_create_here' => $this->xpdo->lexicon('copyrightedresource_create_here'),
                      );
                    }
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                    • I don't think that's it -- I've put that in my CRC, and the text I supplied shows in the right-click menu, but not at the top of the page. I noticed that even the Articles plugin displays "New Document" when creating a new article.