We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    In developing a plugin to make Static Resources work with Media Sources, I find the need to specify a given Media Source. How would I do that?
    $source = (media source #2) ??? 
    $basepath = $source -> getBasePath();
      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
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Looks like there's some custom thing in there handling those... I would guess that you could instantiate or retrieve items using the modMediaSource class. Have you looked at the http://github.com/argnist/StaticSaver plugin? I don't think it creates the media sources programmatically, however...
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        That's where I got the getBasePath function from. But there is at least one extended class, so I'm not sure which one I should be using, or how I would instantiate a modMediaSource object for a given media source.

        What I am doing now is using a chunk with the path set in the given Media Source. Static resources can use a Media Source, since it uses the File Browser. But all it gets is the path in the File Browser. There's no way to indicate to the static resource on page load that it needs to get the static file from a Media Source base path.

        So I have a plugin using OnLoadWebDocument to prefix the static resource's saved path with the base path.
            case 'OnLoadWebDocument':
                /* add the path to the resource content */
                if($modx->resource->get('class_key') == 'modStaticResource') {
                    $path = $modx->getChunk('Path');
                    $modx->resource->set('content', $path . $modx->resource->get('content'));  
                }
          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