I am using Media gallery module to create gallery and pathauto module to generate URL.

For a gallery page I use this pattern for URL


When user will click on any photo. I am showing that image on different page.

But I am not getting way to set path for page where the single image will be displayed.

Automatic it generates URL like this


Is there any way around this? Any help will be appreciated.

2 Answers 2


The solution that Letharion posted will work fine, but making integration with path auto is a better solution like (s)he writes.

Doing this in not that hard, but it can be a bit tricky to do the first time.

To do it you need a few steps.

  1. First you need to implement hook_pathauto in order to get the setting for how the alias should look like. Here you can give info about which type of token can be used for path replacements etc.

  2. Second you need to create a function which can be used to generate an alias. It should look something like this.

    function foo_pathauto_update_alias($file, $op, array $options = array()) {
      module_load_include('inc', 'pathauto');
      $path = media-gallery/detail/' . $file->bid . '/' . $file->fid
      pathauto_create_alias('aug_product', $op, $path, array('file' => $file));

    Path auto is based on entities. So you need to be able to generate the path from a single entity. In this case the file that's created. By using the above function structure you can use a single function and utilize it for bulk updates as well as regular updates while keeping path auto functionality intact.

  3. Lastly you need to call your update function when file is created or updated. This will handle path alias creation. Doing it this way, you can also get path auto to update path alias if the data is changed and the alias should be different, if you want to do so. There is settings for this in the path auto module.

  4. For bonus you can choose to create a bulk update function, that will enable you to the alias for any file created. It takes a bit of work, but should work nicely.

Note doing it this way, it will be a good idea to use the file entity module, as it allows you to handle files like entities, which fits path auto a lot.

  • Nice, up-voted. I would like to add, that this should be submitted as a patch against the media-gallery module for bonus credit :)
    – Letharion
    Commented Jan 3, 2012 at 21:06

Media-gallery registers the "media-gallery/detail/%node/%file" path, meaning you can add an alias onto it.

Upon saving the gallery, you could with a form_alter create path aliases for each gallery image, which should solve your problem.

function hook_form_ID_alter($form) {
  foreach($form['images'] as $image) {
    path_save(array('sources' => $image->path, 'dest' => 'pretty-url'));

A cooler solution would be direct pathauto integration, but I'm not knowledgeable enough to tell you what is required to get that working.

  • Adding path to each gallery image will be a static solution. It will fail when user add new image. Commented Jan 3, 2012 at 5:47
  • I don't see why that would be? On the next save, the process would repeat itself automatically, if well written.
    – Letharion
    Commented Jan 3, 2012 at 7:13
  • Can you elaborate more how can i do this with form_alter? Commented Jan 3, 2012 at 9:28
  • I added a pseudo code example of how I thinking.
    – Letharion
    Commented Jan 3, 2012 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.