We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I've been trying to figure out if there is an option or way to configure Migx to use the parent objects ID for the "resource specific media source" - in this case it is actually an "object specific media source" since there is not resource involved. ANYWAY the object specific resource works just fine when using the upload files or load from media sources from the nested grid - the source points to:

    [[migxObjectMediaPath? &pathTpl=`assets/projects/{id}/images/` &createFolder=`1`]]

    no issues, folders are created matching the main object id.... files uploaded. HOWEVER, if I click on one of the rows in the grid (after an upload or multi upload) to edit/change the image (or add a new image) from the popup form. clicking on the file field in that form tries to create a new directory based on the new Image Object ID and not the Parent Object ID (in this case a "Project")

    I added some debugging to the migxObjectMediaPath snippet and I see that there is no information about the parent object passed from the popup form.

    How can I pass that information to the migxObjectMediaPath snippet using Migx/configs - or do I have to write a new snippet ( migxParentObjectMediaPath ) in order to do this?

    Here is my code for migxObjectMediaPath:

    <?php
    
    $modx->log(MODX_LOG_LEVEL_ERROR, '[migxObjectMediaPath]: $_REQUEST = ' . print_r($_REQUEST,TRUE));
    
    $modx->log(MODX_LOG_LEVEL_ERROR, '[migxObjectMediaPath]: $scriptProperties = ' . print_r($scriptProperties,TRUE));
    
    $modx->log(MODX_LOG_LEVEL_ERROR, '[migxObjectMediaPath]: $_SESSION['migxWorkingObjectid'] = ' . print_r($_SESSION['migxWorkingObjectid'],TRUE));
    
    $pathTpl = $modx->getOption('pathTpl', $scriptProperties, '');
    
    $objectid = $modx->getOption('objectid', $scriptProperties, '');
    
    $createpath = $modx->getOption('createFolder', $scriptProperties, true);
    
    $path = '';
    
    //$createpath = false;
    
    if (empty($objectid) && $modx->getPlaceholder('objectid')) {
        // placeholder was set by some script on frontend for example
        $objectid = $modx->getPlaceholder('objectid');
    }
    if (empty($objectid) && isset($_REQUEST['object_id'])) {
        $objectid = $_REQUEST['object_id'];
    }
    
    if (empty($objectid)) {
    //$modx->log(MODX_LOG_LEVEL_ERROR, '[migxObjectMediaPath]: $_REQUEST[objectid] is empty');
        //set Session - var in fields.php - processor
        if (isset($_SESSION['migxWorkingObjectid'])) {
            $objectid = $_SESSION['migxWorkingObjectid'];
            $createpath = !empty($createfolder);
        }
    
    }
    
    $path = str_replace('{id}', $objectid, $pathTpl);
    //$modx->log(MODX_LOG_LEVEL_ERROR, '[migxObjectMediaPath]: $path = ' . $path);
    
    $fullpath = $modx->getOption('base_path') . $path;
    $modx->log(MODX_LOG_LEVEL_ERROR, '[migxObjectMediaPath]: $fullpath = ' . $fullpath);
    $modx->log(MODX_LOG_LEVEL_ERROR, '[migxObjectMediaPath]: $createpath = ' . $createpath);
    
    if ($createpath && !file_exists($fullpath)) {
        $permissions = octdec('0' . (int)($modx->getOption('new_folder_permissions', null, '755', true)));
        if (!@mkdir($fullpath, $permissions, true)) {
            $modx->log(MODX_LOG_LEVEL_ERROR, sprintf('[migxResourceMediaPath]: could not create directory %s).', $fullpath));
        }
        else{
            chmod($fullpath, $permissions); 
        }
    }
    
    return $path;



    the error log from the file upload dialog when uploading directly to the grid:
    (this works, in this case the parent object id is 52, so I just look for either object_id or co_id in the request.)

    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 2) [migxObjectMediaPath]: $_REQUEST = Array
    (
        [fileapi152942778613211] =>
        [action] => browser/file/upload
        [wctx] =>
        [source] => 3
        [path] => /
        [configs] => Images
        [object_id] => 52
        [reqConfigs] => projects
        [HTTP_MODAUTH] => modx5ab015f2b73a82.23231518_15b2900dc67d8a3.03067517
        [_file] => win002.jpg
    )
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 4) [migxObjectMediaPath]: $scriptProperties = Array
    (
        [pathTpl] => assets/projects/{id}/images/
        [createFolder] => 1
    )
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 42) [migxObjectMediaPath]: $fullpath = domain.com/assets/projects/52/images/
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 43) [migxObjectMediaPath]: $createpath = 1
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 2) [migxObjectMediaPath]: $_REQUEST = Array
    (
        [action] => mgr/migxdb/process
        [processaction] => loadfromsource
        [configs] => Images
        [resource_id] => 0
        [co_id] => 52
        [reqConfigs] => projects
        [source] => 3
        [extra_params] =>
        [HTTP_MODAUTH] => modx5ab015f2b73a82.23231518_15b2900dc67d8a3.03067517
    )
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 4) [migxObjectMediaPath]: $scriptProperties = Array
    (
        [pathTpl] => assets/projects/{id}/images/
        [createFolder] => 1
    )
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 42) [migxObjectMediaPath]: $fullpath = domain.com/assets/projects/52/images/
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 43) [migxObjectMediaPath]: $createpath = 1



    This however is what happens when I click on the file field in the popup form:
    (upload a file to the grid, right click it > edit it & click on the file field.)


    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 2) [migxObjectMediaPath]: $_REQUEST = Array
    (
        [id] => 1
        [action] => source/getlist
        [HTTP_MODAUTH] => modx5ab015f2b73a82.23231518_15b2900dc67d8a3.03067517
    )
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 4) [migxObjectMediaPath]: $scriptProperties = Array
    (
        [pathTpl] => assets/projects/{id}/documents/
        [createFolder] => 1
    )
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 42) [migxObjectMediaPath]: $fullpath = domain.com/assets/projects/40/documents/
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 43) [migxObjectMediaPath]: $createpath =
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 2) [migxObjectMediaPath]: $_REQUEST = Array
    (
        [id] => 1
        [action] => source/getlist
        [HTTP_MODAUTH] => modx5ab015f2b73a82.23231518_15b2900dc67d8a3.03067517
    )
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 4) [migxObjectMediaPath]: $scriptProperties = Array
    (
        [pathTpl] => assets/projects/{id}/images/
        [createFolder] => 1
    )
    
    (ERROR @ domain.com/core/cache/includes/elements/modsnippet/12.include.cache.php : 42) [migxObjectMediaPath]: $fullpath = domain.com/assets/projects/40/images/
    




    See - no information about the parent object - which happens to be 52 here, in our last line it is trying to create a path based on the image ID which happens to be 40 here & it gets that from a session variable: $_SESSION['migxWorkingObjectid']





    How do I fix this? - or do I have to write a new snippet for the media source?

      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525