How a module can override theme suggestion? Basically it was How to tell Drupal to look for templates in module directory? but I'll reword it, as I don't want to define a new theme (reason was already given).

What I want to do: in my module I have a file node--attach.tpl.php which is a modifed version of node.tpl.php. Now I want that, if view_mode = 'attach' then this file is used. Also, theme should be allowed to override it with its own node--attach.tpl.php in theme folder.
This code works for me:

function MYMODULE_theme_registry_alter(&amp;$theme_registry) {
  $mod_path = drupal_get_path('module', 'MYMODULE');

  $theme_registry_copy = $theme_registry;       // munge on a copy
  _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'pow', $mod_path);
  $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);

  $hooks = array('node');
  foreach ($hooks as $h) {
    if (!isset($theme_registry[$h]['theme paths'])) { 
      $theme_registry[$h]['theme paths'] = array(); 
    } 
    _MYMODULE_insert_after_first_element($theme_registry[$h]['theme paths'], $mod_path);
  }
}

function _MYMODULE_insert_after_first_element(&amp;$a, $element) {
  if(is_array($a)) { 
    $first_element = array_shift($a); 
    if ($first_element) { 
      array_unshift($a, $first_element, $element); 
    } 
    else { 
      array_unshift($a, $element); 
    }
  }
}

function MYMODULE_preprocess_node(&amp;$vars) {
  if ($vars['view_mode'] == 'attach') {
    $vars['theme_hook_suggestions'][] = 'node__attach';
  }
}


I know you've seen nearly that exact code before from looking at your other question, but there are a couple of changes from the code in the article. It should work after clearing the caches (just once!)

Using the above I added a file called node--attach.tpl.php to my module folder, cleared the caches again, and the output from that template file was shown for the node.

Then I added node--attach.tpl.php to my theme folder, cleared the caches again, and the output from the new template file was shown.