We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37099
    • 338 Posts
    I'm trying to figure out how to use MyComponent.

    What I did so far I followed the instructions: "Building and Installing the Example Project" from about halfway down the page at http://bobsguides.com/mycomponent-tutorial.html

    Is Example supposed to work as it is (ie show the CMP page) immediately after you bootstrap it?

    If I built it and copied it to another MODX install it worked ok, i think because the the files are in the expected place ( assets/components/ core/components/)

    Are you supposed to add the example.core_path system settings and put that in your files like in the Doodles tutorial?

    Thanks
    Mike
      • 3749
      • 24,544 Posts
      For the Example CMP to work, you have to run Bootstrap, ExportObjects, (optionally, LexiconHelper with both rewrite code files and rewrite lexicon files set to true in the project config file), then Build.

      At that point, the Example project will show up in Package Manager and you can install it. Once it's installed and you reload the Manager page, the Example CMP should show up in the Components menu.
        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
        • 3749
        • 24,544 Posts
        BTW, the steps are all here: http://bobsguides.com/mycomponent-tutorial.html in the "Building and Installing the Example Project" section. wink
          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
          • 37099
          • 338 Posts
          Does it work like this?:

            • 37099
            • 338 Posts
            It's not going to work with custom tables is it?

            I couldn't do the equivalent of the Doodles functionality with this method could I?

            At least I could start it off but then would have to build the resolvers and transport package builder by hand.
              • 3749
              • 24,544 Posts
              Nice diagram! It's almost correct.

              The right-hand box ( ... /assets/) should say something like "work on your CSS, JS, Image or Media files"

              Also, I think it would be clearer if the "Add Object" arrow pointed to the "Edit Config File" box and it didn't have an arrow below it.

              It's slightly more complicated because if you add a new object to the project config file and there is a correctly named and located code file for that object (or you specify its filename in the config file). The code file will be used instead of a stub file, though I think it will get the license and headings injected if they are missing.

              To answer your questions. It's not going to create a resolver that will create any DB tables (though it will create a generic resolver and you could put the code to do that there). If you wanted to create some existing rows in the Doodles table and have them installed, you'd have to do that in the resolver as well, though there's no reason to do it. Doodles just needs the class files to function. The tables can be empty to begin with.

              If you have generated the class and map files for any custom tables from the schema, though, and put them in the right place in the structure. MyComponent will put them in the transport file automatically and they'll be installed properly with the package. It will also create and install the menu item and corresponding action for you if they're specified in the project config file.

              One thing to remember is that, except for "official" MODX objects (chunks, snippets, etc.) and creating the tables and the menu/action, Doodles (and pretty much every other project) is just files -- either under the project's assets or core directories. Those files will all go to the right place automatically, even if they're not specified in the project config file. MyComponent basically takes the whole project assets directory and installs it at /assets/components/componentname and the entire project assets directory and installs it at core/components/componentname, preserving the structure in both cases.



              Since 99.9% of the time, that's every file needed by the project, the files are all handled automatically even if they're not in the project config file, and installing them doesn't require re-running Bootstrap, ImportObjects, or ExportObjects (though Bootstrap and ExportObjects should always be run at least once).



                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
              • MyComponent basically takes the whole project assets directory and installs it at /assets/components/componentname and the entire project assets directory and installs it at core/components/componentname, preserving the structure in both cases.
                Don't you mean "...and the entire project components directory and installs it at core/components/componentname..."?
                  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
                  • 3749
                  • 24,544 Posts
                  No, anything in the assets/mycomponents/componentname/assets/components/componentname/ directory goes to the assets/components/componentname/ directory on install.

                  Only the files in the assets/mycomponents/componentname/core/components/componentname/ directory go to core/components/componentname/.

                  That's basically true for almost all packages (though without the assets/mycomponents/componentname prefix on their development locations), not just MyComponent ones.

                  See, for example, https://github.com/splittingred/Articles.

                  The core/components/articles/ files go to core/components/articles/ on install.

                  The assets/components/articles/ files go to assets/components/articles/ on install.

                  Presumably, in their development location, Shaun has some prefix for them equivalent to assets/mycomponents/componentname/, but since the git root of the local project is in that directory, it doesn't show up at GitHub (nor does assets/mycomponents/componentname/ for mine).
                    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
                    • 37099
                    • 338 Posts
                    Hi Bob,

                    Thanks for the info. I've updated my diagram, I hope I'm understanding it better now?





                      • 3749
                      • 24,544 Posts
                      Yes, that looks very good. It's interesting that I have to study each iteration of your diagram to think of corrections. It shows that I've never thought very hard about MC in terms of a flow chart. wink

                      If I could suggest a few more tweaks to make it perfect:

                      1. In the "Edit Config File" box, add 'Specify the objects you need' at the beginning.

                      2. Move the dashed arrow at the lower left above Lexicon Helper, which is generally the last thing you want to do before the build (and your resolver might use the lexicon).

                      3. In the box on custom DB files, change recreate to create.

                      4. Also in that box, change "write the resolver" to "write the resolver code" (since MC will create a resolver for you).

                      5. Title the two middle boxes: "File System" and "MODX Manager/DB"

                      6. Add "classes" to the list in the left-hand box.

                      7. Move the section "and your CSS, JS ... " to the left-hand box, since they belong in the File System section.

                      8. Capitalize CSS and JS.

                      9. Change the arrow coming out of "Import Objects" to point to the "MODX Manager/DB" box. (since you're really importing the objects into the Manager/DB and exporting them from there).

                      10. Remove the phrase "and they will work immediately .. " from the left-hand box, since it's not necessarily true there.


                      I really appreciate your creating the diagram. Is it OK if I use the finished version in the docs (and if so, what format is the file in)?
                        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