I can't seem to get preprocess functions working in a module. Here's the relevant excerpt from my .module file:


function mymodule_theme($existing, $type, $theme, $path) {
  $module_path = drupal_get_path('module', 'mymodule');

  $theme = array();
  
  $theme['views_view_table__user_vendors'] = array(
    'template' => 'views-view-table--user-vendors',
    'arguments' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL),
    'path' => $module_path . '/templates',
    'base hook' => 'views_view_table',
    'type' => 'module',
    'theme path' => $module_path,
    'preprocess functions' => array(
      'template_preprocess',
      'template_preprocess_views_view_table',
      'mymodule_preprocess_views_view_table__user_vendors',
    ),
  );  
  return $theme;
}

/**
 * This preprocessor should show the variables.
 */
function mymodule_preprocess_views_view_table__user_vendors(&$vars) {
  dpm($vars);
}

In addition,

  • The template file exists, and is being recognized/used to output the table.
  • mymodule's weight is set higher than Views' weight

I'm hoping I'm missing something simple. Can anyone suggest anything?

Thank you!

Comments

JFreed’s picture

Hello
Did you get any where with this I seem to be having the same problem.
J

jmcintyre’s picture

I've resorted to using preprocessor functions for the default Views template ('mymodule_preprocess_views_view_table' in my example), and using logic in the function to identify whether the element being rendered is the one I want to handle. Example:

function mymodule_preprocess_views_view_table(&$vars) {
  if ($vars['view']->name == 'my_target_view' && $vars['view']->current_display == 'my_target_display_id') {
    // Do some stuff here
  }
}

Another change from my original example: because we're working with Views' default theme implementation for the element, there's no need to identify a preprocessor function in hook_theme().

You can still create a custom tpl.php file with the same namespace structure as before, and Views will pick it up upon theme registry rebuild.

mustanggb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)