We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42701
    • 47 Posts
    Hi,
    I'm using MyComponent 3.0.4 and have run into a roadblock. I have edited the config.php file to bundle my project's elements and package them up, but I can't seem to do the same for my css, js, and image files. Is this not supported in the 3.x version of MyComponent, or is there something I'm overlooking?
      • 3749
      • 24,544 Posts
      Yes, it's definitely supported. If you specify their directories in the config file and have hasAssets => true, they should be included automatically.

      Even if you don't specify them in the config file, they will be included if they're in the right place and hasAssets is set to true. They should go under assets/mycomponents/componentname/assets/componentname/.

      Anything below that will be included if hasAssets is true.
        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
        • 42701
        • 47 Posts
        Thanks Much,

        I am able to package all my assets files now by putting them in the right directory. But I want to package everything in my assets/components (e.g. gallery, tinyMCE) dir into the project. You mentioned being able to specify the directory in the config file to do this, but for the life of me I can't figure out how. How would one specify the specific directory in the config file to grab all the assets from? Also, is there a way to eliminate the "component/name" dir from the target directory when the package is installed in a new modX?
          • 3749
          • 24,544 Posts
          You'd have to modify the build.transport.zip file to do it. You can specify any source and target directories and you can have as many file resolvers in build.transport.php as you like. Modify the $sources array near the top of the file to add the new source directories and do something like this:


          if ($hasAssets && $i == 1) {
                  $helper->sendLog(MODX::LOG_LEVEL_INFO, 'Packaged some assets directory files');
                  $vehicle->resolve('file',array(
                      'source' => $sources['extra_source_assets'],  
                      'target' => "return MODX_ASSETS_PATH . 'somedirectory/';",
                  ));
          
                  $helper->sendLog(MODX::LOG_LEVEL_INFO, 'Packaged some more assets directory files');
                  $vehicle->resolve('file',array(
                      'source' => $sources['other_source_assets'],  
                      'target' => "return MODX_ASSETS_PATH . 'some_other_directory/';",
                  ));
          
                  // of if you want the files directly under the MODX assets directory:
          
                  $helper->sendLog(MODX::LOG_LEVEL_INFO, 'Packaged assets directory files');
                  $vehicle->resolve('file',array(
                      'source' => $sources['some_other_source_assets'],  
                      'target' => "return MODX_ASSETS_PATH;",
                  ));
          }


          Note that in the older verion of MyComponent, you can also transfer packages (e.g., TinyMCE) as packages, which you can then search locally for in Package Manager and install, though you give up notifications of updates since they didn't come from the MODX repo. TBH, I can't remember if this option works in the current version. It did at one time, but I haven't tested it since I refactored MyComponent and can't remember if I finished it.

          Being able to name packages in the config file and have them automatically installed with no further work is on the Roadmap, but probably won't come any time soon.

          You don't want to mess with the locations of the core files or the Lexicon won't work. If you were creating a package for submission as an extra, I'd strongly recommend against moving assets files, but I can see why you might want to do it for your own use. I like having them in the standard locations (under assets/components/component_name) because it makes it easier for me to write code that will work in both the development and installed versions, makes it easier for folks to find them, and keeps the assets directory less cluttered.


            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
            • 12066
            • 48 Posts
            Hi @BobRay,

            thanks for MyComponent, it's just incredible!

            I didn't found anything in the forums, so I decided to post it in this thread. If there is a thread answering my following question please point me to it.

            Does MyComponent supports creation of database tables by a schema (xml)?
            If yes, I would be really glad if you could give me a tip or guide how to succeed...

            Thanks.

              • 3749
              • 24,544 Posts
              Sorry, not at this time. I assume that you mean creating them when the package is installed.

              There are at least a couple different ways to do this with a custom resolver.

              1. You can create the class and map files locally using $modx->parseSchema() to put them in the project's core directory where they'll get transferred.

              2. You could also transfer the schema and use parseSchema() in your resolver to create them on the user's machine during the install.

              In either case, your resolver needs to create the tables, which is fairly easy. See this:

              https://github.com/modxcms/Discuss/blob/release-1.1/_build/resolvers/resolve.tables.php

              The Discuss package uses the first method, which I think is probably more sensible. You can see the class and map files in the model directory.

              In theory, MyComponent could do all that based on the schema, but you'd have to test everything fully locally before packaging it, so you'd already have the class and map files and they might as well be in the right place for transfer. Then, all your resolver needs to do it create the tables and, if necessary, put data in them.

                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
                • 12066
                • 48 Posts
                @BobRay,

                thanks for that. Works as expected!