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
    Actually, the desired media path isn't attached to the resource as much as it's attached to the Resource Browser being used by the RTE. Perhaps some mechanism of dynamically assigning the resource browser Media Source...

    I checked resource groups, but they don't have anything to do with Media Sources.
      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
      • 4172
      • 5,888 Posts
      this seems to work (with image-tv):

      mediasource path and url:

      assets/[[getUltimateParentFolder]]/


      <?php
      
      $level = $modx->getOption('level', $scriptProperties, 1);
      
      if (isset($modx->resource))
      {
          //seems we are at frontend, get the actual resource-id
          $id = $modx->resource->get('id');
      } else
      {
          $parsedurl = parse_url($_SERVER['HTTP_REFERER']);
          $strings = explode('&', str_replace('& amp;', '&', $parsedurl['query']));
          // & amp;  without the space!!! , the forums here converts it to an & 
      
          if (count($strings) > 0)
          {
              foreach ($strings as $string)
              {
                  $q = explode('=', $string);
                  if (count($q == 2))
                  {
                      $get[$q[0]] = $q[1];
                  }
              }
      
              $debug['get'] = $get;
              /* 
              $chunk = $modx->getObject('modChunk', array('name' => 'debug'));
              $chunk->setContent($chunk->get('snippet') . print_r($debug, 1));
              $chunk->save();
              */
              if (isset($get['parent']))
              {
                  //seems we are working on a new resource at backend, get the parent here
                  $id = $get['parent'];
              } elseif (isset($get['id'])) //seems we are working on a resource at backend, get the id here
      
                  $id = $get['id'];
              {
              }
          }
      }
      
      if (isset($id))
      {
          $parentIDs = $modx->getParentIds($id, 10, array('context' => 'web'));
          $parentIDs = array_reverse($parentIDs);
          $ultimateParent = count($parentIDs) > 1 ? $parentIDs[$level] : $id;
          /*
          $debug['parentids'] = $parentIDs;
          $chunk = $modx->getObject('modChunk', array('name' => 'debug'));
          $chunk->setContent($chunk->get('snippet') . print_r($debug, 1));
          $chunk->save();
          */
          if ($parentObj = $modx->getObject('modResource', $ultimateParent))
          {
              /*
              $debug['pagetitle'] = $parentObj->get('pagetitle');
              $chunk = $modx->getObject('modChunk', array('name' => 'debug'));
              $chunk->setContent($chunk->get('snippet') . print_r($debug, 1));
              $chunk->save();
              */
              return $parentObj->get('pagetitle');
          }
      }
      //get the ultimate parents pagetitle
      
      
      return '';
      
      
      [ed. note: Bruno17 last edited this post 14 years, 2 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3749
        • 24,544 Posts
        Nice.

        BTW, it might be safer in the long run to use this to check whether you're in the front end (in case $modx->resource gets set in the Manager down the road):

        if ($modx->context->get('key') != 'mgr')



        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html


          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