We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42562
    • 1,145 Posts
    donshakespeare Reply #51, 8 years ago
    Thanks @sottwell.

    Okay, I managed to solve the issue of #1

    Dug deep and found templateVars transport file:
    assets\mycomponents\myExtra\_build\data\myExtra\transport.tvs.php

    Replaced all instances of
    'default_text' => '[[++assets_url]]components/....

    with
    'default_text' => MODX_ASSETS_URL.'components/...


    UPDATE
    The above is pure falsehood. It renders your url instead of target url - bad bad bad!

    UPDATE
    I scrapped the default value of TV - can't find a suitable way to make it work

    In mycomponent/myExtra/_build/resolvers/resource.resolver.php
    Using Resource Resolver to set value - only this resource will have the value, oh well, but it works
    $intersects = array (
                    0 =>  array (
                      'pagetitle' => 'myExtra',
                      'parent' => '0',
                      'template' => 'myTemplate',
                      'tvValues' =>  array (
                        'myTV' => MODX_ASSETS_URL.'components/...',


    For #2

    if I tweak the category.resolver.php, would that cater for installation or non-installation of user-choices?

    I don't see a resolver for assets folders. I want user to choose to install this or that folder... still looking [ed. note: donshakespeare last edited this post 8 years ago.]
      TinymceWrapper: Complete back/frontend content solution.
      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • 3749
      • 24,544 Posts
      I think this will work if you have your TV set to preprocess, though I've never tried it:

      'default_text' => '[[++assets_url]]components/....


      In the config file, there's a 'hasAssets' member that should transfer all your projects's assets files automatically. If you want to be selective, you can add a file resolver to build.transport.php.
        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
        • 42562
        • 1,145 Posts
        donshakespeare Reply #53, 8 years ago
        I think this will work if you have your TV set to preprocess, though I've never tried it:
        How do I force TV to preprocess its tags even in the Manager?
        Are you referring to properties property set "Pre-process tags in Property Values"?

        build.transport.php.
        Thanks for the direction. I will attempt to add some logic to that file.
        Initially I thought that file took care only of creating transport package, and not resolving stuff upon installation; but I guess it does both.
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 3749
          • 24,544 Posts
          build.transport.php builds the whole package. It's the one file that MyComponent won't ever mess with, so you can add stuff to it and it will stick.

          Sorry, I meant a file vehicle, not a file resolver. For a file vehicle, you just set the source directory on your machine and the target directory on the user's machine and the files get packaged and transferred.

          See the code in build.transport.php for moving the core and assets directories. Again, if you want the whole local assets directory from your project, all you have to do is set the 'hasAssets' member to true in the project config file. The code is already there to move it.

          You're right -- I was thinking of the "Pre-process tags in properties" setting. I don't think that will do what you want. You could set that default value in your generic resolver (the one named for your package -- assuming that you asked for it in the project config file), though. The TV will be in place by the time that resolver runs and you can get it by name, set the default value, and save it.
            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
            • 42562
            • 1,145 Posts
            donshakespeare Reply #55, 8 years ago
            Sorry, I meant a file vehicle, not a file resolver. For a file vehicle, you just set the source directory on your machine and the target directory on the user's machine and the files get packaged and transferred.
            So I can add logic here to interact with install options? Add more arrays according to my folder choice?
                /* This section transfers every file in the local
                   mycomponents/mycomponent/assets directory to the
                   target site's assets/mycomponent directory on install.
                 */
            
                if ($hasAssets && $i == 1) {
                    $helper->sendLog(modX::LOG_LEVEL_INFO,
                        $modx->lexicon('mc_packaged_assets_files'));
                    $vehicle->resolve('file', array(
                       'source' => $sources['source_assets'],
                        'target' => "return MODX_ASSETS_PATH . 'components/';",
                         ));
                }


            You could set that default value in your generic resolver (the one named for your package -- assuming that you asked for it in the project config file),
            I have beeeeen looking high and low for this generic/default resolver, did not know I had to specify it...
            So I specified like so but myExtra.resolver.php does not appear in my _build/resolvers folder

                 * 'default' creates a default resolver named after the package.
                 * (other resolvers may be created above for TVs and plugins).
                 * Suffix 'resolver.php' will be added automatically */
                'resolvers' => 'default',


            UPDATE
            After putting back my head on, the above line of code is wrong

            It should be...

                'resolvers' => array(
                    'default',
                    'addUsers',
                    'etc etc'
                ),
            [ed. note: donshakespeare last edited this post 7 years, 11 months ago.]
              TinymceWrapper: Complete back/frontend content solution.
              Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
              5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
              • 3749
              • 24,544 Posts
              Right, just add more of these:

              $vehicle->resolve('file', array(
                     'source' => $sources['source_assets'],
                      'target' => "return MODX_ASSETS_PATH . 'components/';",
                       ));


              It's a separate line of code. I don't think you can add to the original array. The line creates a single resolver that moves one directory full of files.

              IIRC, there is also something called a "file vehicle" that will move files if you have no other object to to attach them to.
                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
                • 42562
                • 1,145 Posts
                I fear as I am getting closer, I am losing hope. But this thing, I will get eventually.

                build.transport.php builds the whole package. It's the one file that MyComponent won't ever mess with, so you can add stuff to it and it will stick.
                It appears that this file will not take $modx->getOption('userSelection', $options) - the variable $options means nothing at the point of its execution

                That line works in resolvers.

                If I put that line in my resource.resolver, the resources still get installed(transported) but, now obviously, its properties and fields are not resolved (no parent, template etc, the resources are, understandably, scattered in resource tree upon installation)

                The author of this post shared his final codes with a caveat that his extra does not enjoy a clean extra.
                https://forums.modx.com/thread/96795/need-to-run-the-resource-resolver-php-only-if-add-content-option-is-checked-at-install
                He prevents build.transport.php from doing installation
                 `$hasResources = false;`


                And his additional resolver is this
                <?php
                $sources = array(
                    'data' => $modx->getOption('core_path') . 'components/solo/contentResources/',
                );
                ​
                $addContent = $modx->getOption('add_content', $options, false);
                ​
                /* Add transport.resources if addContent is selected */
                ​
                if ($addContent) {
                  $modx->log(modX::LOG_LEVEL_ERROR, 'addContent is true');
                  $resources = include $sources['data'] . 'transport.resources.php';
                  foreach ($resources as $resource) {
                    $resource->save();
                  }
                  $modx->log(modX::LOG_LEVEL_ERROR, 'transport.resources done');
                }
                ​
                return true;


                Any hints as to how I can do this and yet have a clean unistall?
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                  • 3749
                  • 24,544 Posts
                  Sorry, I've kind of lost track of what this conversation is about. I thought you were talking about moving files, but now it seems to be resources (and maybe other MODX objects?). And you want the user to have some control over something, but I'm not sure what.

                  Can you refresh my memory on exactly what it is you're trying to do, and why?
                    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
                    • 42562
                    • 1,145 Posts
                    Thanks for helping out a great deal... I went ahead and packaged my Extra; I could get me head around making creating resources and assets particular folders optional.
                    To recap, here are my initial questions

                    https://forums.modx.com/thread/86192/trying-to-use-mycomponents?page=5#dis-post-540805
                    donshakespeare Reply #49, 1 week, 3 days ago
                    Okay, I am back.
                    I have three mild questions that are stumping me immensely

                    #1. Is it possible to set default value of file/image TVs with user's assets' url (no MODX tag)? Something like MODX_ASSETS_URL translated server-side to proper url
                    [[++assets_url]] works okay in the frontend, but in the Manager, phpThumb will not parse MODX tags and thus throw a thousand errors each time. (ANSWERED BELOW)

                    #2. I have been trying to understand user input and default resolver and all, but no progress. I want to make a LITE version of my Extra. I don't want certain asset folders to be installed, and chunks and demo resources (ANSWER: ...PENDING)
                    PROBLEM:
                     $modx->getOption('userInstallOption', $options) 
                    only works in resolver files. But objects have already been created before resolver file fires sad

                    #3. Does MyComponent respect the new dependency thing I am hearing about? Main Extra won't install unless all subpackages have been installed. (ANSWER: NO)

                    Many thanks in advance.

                    For anyone else in need of understanding, always follow very closely BobRay's tutorial/instructions; he very often foresees and clears the caches of yours and my stupidity.

                    Answer to #1
                    MODX image TV has an annoying phpthumb script that insists on showing you a thumbnail of your image. This means, you have to get the url right, I mean relatively right, or else there will be a billion error reports in your log.
                    Say you are in site.com/manager/....
                    Your image TV input field, to preview an image in your assets folder must have something like ....(absolutely no absolute URLs here watch out!)
                    assets/component/myExtra/images/bliss.jpg

                    If you wish your Extra to have default_text in an image TV, you'll have to do this maneuver upon installation since it would be foolhardy to guess that the target user has not renamed his assets folder. How do you get the name of the target assets folder?

                    In your main config file:
                     C:\modxLocal\core\components\mycomponent\_build\config\myExtra.config.php

                    find and alter
                        /* ********************************************* */
                        /* (optional) Array of extra script resolver(s) to be run
                         * during install. Note that resolvers to connect plugins to events,
                         * property sets to elements, resources to templates, and TVs to
                         * templates will be created automatically -- *don't* list those here!
                         *
                         * 'default' creates a default resolver named after the package.
                         * (other resolvers may be created above for TVs and plugins).
                         * Suffix 'resolver.php' will be added automatically */
                        'resolvers' => array(
                            'default'
                        ),
                    If for some reason you have this, look in example.config.php

                    'default' means, when you bootstrap/ Export Objects in MyComponent, myExtra.resolver.php will be created in
                    C:\modxLocal\assets\mycomponents\myExtra\_build\resolvers\

                    Luckily, this file is untouched once created - so you can edit it however you want.
                    I even copied over all my edits from resource.resolver.php to this file - I don't want anything lost each time I rerun MyComponent.

                    The code in this resolver file will run upon installation, after your MODX objects shall have been created on the target's site
                    $tv = $modx->getObject('modTemplateVar', array('name' => 'myExtraImageTV'));
                    $tv->set('default_text', basename(MODX_ASSETS_URL).'/components/myExtra/images/bliss.jpg');
                    $tv->save();

                    Why is this insufficient?
                    MODX_ASSETS_URL.'/components/myExtra/images/bliss.jpg';

                    Well, it would give you an unwanted absolute url, and phpthumb cannot handle that
                    /modxRootFolder/assets/component/myExtra/images/bliss.jpg

                    So, basename(MODX_ASSETS_URL) will fetch the last word in MODX_ASSETS_URL which will give the name of the user's assets folder whatever it is.
                    'assets/components/myExtra/images/bliss.jpg';

                    Remember, default_text, not default_value -- very very mucho annoying mistake if you do make it.

                    At this time, you may supply chunks, resources etc with target-specific info.

                    This is me Trying and successfully using the awesome MyComponent.

                    PS.
                    When I use MyComponent my mind immediately asserts:
                    nawhhhh! this definitely has Intelligent Design behind it... I'd sooner believe I was the one who wrote this Extra (me being Mr Trial Error Chance) than believe that the world came from a can of soup.
                      TinymceWrapper: Complete back/frontend content solution.
                      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                      • 3749
                      • 24,544 Posts
                      I'm glad you got things sorted.

                      BTW, this will give you a double slash before 'components/', since all the MODX constant paths and URLs should already end in a slash.

                      MODX_ASSETS_URL.'/components/myExtra/images/bliss.jpg';


                      should be:

                      MODX_ASSETS_URL . 'components/myExtra/images/bliss.jpg';


                      Now I have a question for you. wink

                      I have a recurring mess of those phpThumb errors in the log, even though I don't actually use any image TVs or PhpThumb (and never have). My question is -- can you get that error from an existing image TV even though it's never used? I have a couple of them around for testing things and I'm wondering if just editing a Resource that has a bad image TV attached to its template will throw the error. I bet it does. [ed. note: BobRay last edited this post 7 years, 11 months ago.]
                        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