We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4002
    • 64 Posts
    I am fairly new to modx at this point (couple of months), but have been extremely impressed with it’s flexibility.

    I am about to build a module for a client to be able to manage a section of their website that will be driven by some custom tables outside of the core. I need to integrate the image manager (similar to the way the Image Widget works) into my form to let them select images that have been uploaded to the server so i can save that value to the database.

    Can anyone tell me how to call the image manager in my custom form within my module (I think I see this being done with the Image Widget)?
      • 4018
      • 1,131 Posts
      A basic call might look something like this:

      {$base_url}manager/media/browser/mcpuk/browser.html?Type=images&Connector={$base_url}manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath={$base_url}
      


      You would code it to where $base_url would be the full URL. You could of course use the $site_url variable as well...but I prefer a full URL with a domain name just to be safe. Now, the resource browser expects some parameters. Here they are in detail:

      Type: There are four basic directory paths where the manager stores images and files. The value of ’Type’ reflects this. The four values are ’images’, ’files’, ’media’, and ’flash’.

      Connector: This must be equal to the full path to the proper connector.php file.

      ServerPath: This must be equal to the relative path to the root of your site.

      The resulting URL might look something like this:

      http://www.myserver.com/manager/media/browser/mcpuk/browser.html?Type=images&Connector=/manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=/
      


      Use this URL to create a javascript pop-up. Once the resource browser is opened and an image or file is selected, the browser will attempt to run a javascript function from within the parent window where the browser was called. This function must be named SetUrl and have one parameter for the full URL of the resource. This will allow you to set the value of an element to the full URL of the selected resource from the resource browser. Such a function might look like this (taken from the TinyMCE plugin):

      		function SetUrl( url )
      		{
      			var formObj = document.forms[0];
      			formObj.elements[curFormField].value = url ;
      			if (formObj.width.value && formObj.height.value){
      				resetImageData();
      			}
      			showPreviewImage(document.forms[0].elements[curFormField].value);
      		}
      


      It’s pretty straight-forward once you’ve done it. One of the things we’re hoping to do soon is replace the current resource browser with something else that has a better API with more hooks and better features. smiley

      Jeff
        Jeff Whitfield

        "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
        • 4002
        • 64 Posts
        Perfect. Thanks for the very thorough explanation smiley this is exactly what I needed.
          • 22059
          • 26 Posts
          Hi guys,

          This is a very interesting post. Would you guys (or whoever can do it) be kind enought to post some kind of more details on how to exploit this recommandation ?
          I’m not too good when it comes to programing and I had tried to get around the solution, but some peace are missing to me for beeing able to go further.
          .
          I tried also to exploit File Upload 1.0 snippet mixed with FriendList snippet wich are both very good (one for beeing able to select a file for upload and the other for selecting from a module some information that are stored in a database for further display in a document).
          I have tried to exploit "renderFormElement" function within "includes/tmplvars.inc.php".
          Unfortunatly I’m getting tired of not succeed (lack of MODx/programing knowledge) with doing something that is probably simple :
          -> make a module for enter some information within a database (text, list selection, file upload, image upload).
          -> beeing able to use this information through snippet call.
          So far, I beleive I can manage the all thing, but when it comes to select a file fo upload, upload it and save the full url to the database, I’m stuck.

          May be something is already there doing that ?
          I there an kind of API doc / tutorial for using "renderFormElement" ? (I’m not sure the tv used there can be directly exploitable within the module ...).

          OHO.