<![CDATA[ Dynamic Media Source with MIGX and Babel - My Forums]]> https://forums.modx.com/thread/?thread=86004 <![CDATA[Dynamic Media Source with MIGX and Babel]]> https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474164 http://rtfm.modx.com/display/ADDON/MIGX.Use+resource-specific+media+source+and+multifile-uploader

I'm only interested in the dynamic part (not the multifile-uploader), so I'm only changing basepath and baseurl to:
[[migxResourceMediaPath? &pathTpl=`assets/resourceimages/{id}/`]]


Problem is that I'm also using Babel for multilanguage support, and this particular TV is (and should be) synced between translations. With the solution above I get one folder for each translation, meaning my users have to (in this case) upload a portrait for each translation.

Is there some way of replacing {id} above to always be the ID of the default language resource? Something like:
[[migxResourceMediaPath? &pathTpl=`assets/resourceimages/[[BabelTranslation? &contextKey=`web` &resourceId=`{id}`]]/`]]


Any help appreciated!]]>
mrtnrsl Aug 06, 2013, 11:52 AM https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474164
<![CDATA[Re: Dynamic Media Source with MIGX and Babel]]> https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-564069
Regarding the above did you manage to solve this issue, syncing migx gallery and babel?]]>
kar4fl3x Feb 13, 2019, 12:46 PM https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-564069
<![CDATA[Re: Dynamic Media Source with MIGX and Babel]]> https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474275 mrtnrsl Aug 07, 2013, 11:23 AM https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474275 <![CDATA[Re: Dynamic Media Source with MIGX and Babel (Best Answer)]]> https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474210 http://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474193

seems BabelTranslation is trying to call modResource-methods, but there isn't a modx->resource-object at this time.

you can try to add one with:

<?php

if (!is_object($modx->resource)){
    $modx->resource = $modx->newObject('modResource');
}
$docid = $modx->runSnippet('BabelTranslation', array('contextKey' => 'web', 'resourceId' => $docid));
$modx->log(modX::LOG_LEVEL_ERROR, 'docid migxBabelResourceMediaPath: '.$docid);
]]>
Bruno17 Aug 06, 2013, 06:34 PM https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474210
<![CDATA[Re: Dynamic Media Source with MIGX and Babel]]> https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474193
Things get weird with the snippet call to BabelTranslation, even if i just add:
$modx->log(modX::LOG_LEVEL_ERROR, 'Result: '.$modx->runSnippet('BabelTranslation', array('contextKey' => 'web', 'resourceId' => $docid)));

..in other words, even if if i don't use it the upload won't work.]]>
mrtnrsl Aug 06, 2013, 04:01 PM https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474193
<![CDATA[Re: Dynamic Media Source with MIGX and Babel]]> https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474188 Does the file get uploaded then?]]> Bruno17 Aug 06, 2013, 03:19 PM https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474188 <![CDATA[Re: Dynamic Media Source with MIGX and Babel]]> https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474182
Seems to be pretty straightforward, but something is wrong.
I've added this to my custom snippet:
$docid = $modx->runSnippet('BabelTranslation', array('contextKey' => 'web', 'resourceId' => $docid));


The folder is created, and the snippet returns a correct id (logged it to the error log). However, the MODX browser doesn't like it. When trying to upload a file, the upload never finishes. And the default "No files match blabla" string usually shown in empty folders is gone. And this error strangely occurs even if I only log the code above.

My full snippet is as follows:
<?php
$pathTpl = $modx->getOption('pathTpl', $scriptProperties, '');
$docid = $modx->getOption('docid', $scriptProperties, '');

if (empty($docid) && $modx->getPlaceholder('docid')) {
    $docid = $modx->getPlaceholder('docid');
}
if (empty($docid)) {

    if (is_Object($modx->resource)) {
        $docid = $modx->resource->get('id');
    } else {

        $parsedUrl = parse_url($_SERVER['HTTP_REFERER']);
        parse_str($parsedUrl['query'], $parsedQuery);

        if (isset($parsedQuery['amp;id'])) {
            $docid = $parsedQuery['amp;id'];
        } elseif (isset($parsedQuery['id'])) {
            $docid = $parsedQuery['id'];
        }
    }
}
// Same Media Source for all languages
$modx->log(modX::LOG_LEVEL_ERROR, 'Result: '.$modx->runSnippet('BabelTranslation', array('contextKey' => 'web', 'resourceId' => $docid)));
$docid = $modx->runSnippet('BabelTranslation', array('contextKey' => 'web', 'resourceId' => $docid));

$path = str_replace('{id}', $docid, $pathTpl);
$fullpath = $modx->getOption('base_path') . $path;

if (!file_exists($fullpath)) {
    mkdir($fullpath, 0755, true);
}

return $path;


Any ideas?]]>
mrtnrsl Aug 06, 2013, 02:27 PM https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474182
<![CDATA[Re: Dynamic Media Source with MIGX and Babel]]> https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474169 Bruno17 Aug 06, 2013, 12:45 PM https://forums.modx.com/thread/86004/dynamic-media-source-with-migx-and-babel#dis-post-474169