We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44665
    • 60 Posts
    sebastian-marinescu Reply #1, 8 years, 3 months ago
    Hi MODx-Community,

    I'm making my first transport-package. It's an "MODx-Website"-Package where I try to integrate everything a MODx-Website needs into the package.
    So far I'm packing in: Chunks, Snippets, Templates, TVs, User-Groups, User-Roles and the Package-Attributes (license/readme/changelog).

    MODx allows almost anything to be done via the API, so I'm left with the question:

    Is it possible to create a Dashboard via API and include it in a Transport-Package?

    Thanks in advance for any answer.

    With kind regards,
    Sebastian
      • 44665
      • 60 Posts
      sebastian-marinescu Reply #2, 8 years, 3 months ago
      So I searched around and came to the glorious idea of looking up the core.
      In transport.core.dashboards.php the default-dashboard is created.

      My code will probably now go something like this:

      $dashboards[$i]= $modx->newObject('modDashboard');
      $dashboards[$i]->fromArray(array (
        'id' => 2,
        'name' => 'Editor',
        'description' => 'Dashboard for Editors.',
        'hide_trees' => false,
      ), '', true, true);
      
      [ed. note: sebastian-marinescu last edited this post 8 years, 3 months ago.]
        • 3749
        • 24,544 Posts
        You may want to set the PRESERVE_KEYS attribute to false in your build.transport.php file in case the user already has another dashboard installed. You may also want to set the hide_trees field to true or false.
          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
          • 44665
          • 60 Posts
          sebastian-marinescu Reply #4, 8 years, 3 months ago
          Thanks for the input, BobRay. I added hide_trees for convenience smiley

          And I actually set PRESERVE_KEYS to true, so I can assign the dashboard to an also transported user-group.
            • 3749
            • 24,544 Posts
            If the user already has a dashboard with the ID of 2, your dashboard won't be installed.

            A better method is to set PRESERVE_KEYS to false, then in a resolver that runs late in your package (after the dashboard is installed), find the dashboard by name and set the user-group's dashboard to its ID.

            Of course your method is fine if you're certain that there are no other dashboards installed.
              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