You are here

function views_theme in Views (for Drupal 7) 6.2

Same name and namespace in other branches
  1. 8.3 views.module \views_theme()
  2. 5 views.module \views_theme()
  3. 6.3 views.module \views_theme()
  4. 7.3 views.module \views_theme()

Implementation of hook_theme(). Register views theming functions.

File

./views.module, line 28
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_theme() {
  $path = drupal_get_path('module', 'views');
  require_once "./{$path}/theme/theme.inc";

  // Some quasi clever array merging here.
  $base = array(
    'file' => 'theme.inc',
    'path' => "{$path}/theme",
  );

  // Our extra version of pager from pager.inc
  $hooks['views_mini_pager'] = $base + array(
    'arguments' => array(
      'tags' => array(),
      'limit' => 10,
      'element' => 0,
      'parameters' => array(),
    ),
    'pattern' => 'views_mini_pager__',
  );
  $arguments = array(
    'display' => array(
      'view' => NULL,
    ),
    'style' => array(
      'view' => NULL,
      'options' => NULL,
      'rows' => NULL,
      'title' => NULL,
    ),
    'row' => array(
      'view' => NULL,
      'options' => NULL,
      'row' => NULL,
      'field_alias' => NULL,
    ),
  );

  // Default view themes
  $hooks['views_view_field'] = $base + array(
    'pattern' => 'views_view_field__',
    'arguments' => array(
      'view' => NULL,
      'field' => NULL,
      'row' => NULL,
    ),
  );
  $plugins = views_fetch_plugin_data();

  // Register theme functions for all style plugins
  foreach ($plugins as $type => $info) {
    foreach ($info as $plugin => $def) {
      if (isset($def['theme'])) {
        $hooks[$def['theme']] = array(
          'pattern' => $def['theme'] . '__',
          'file' => $def['theme file'],
          'path' => $def['theme path'],
          'arguments' => $arguments[$type],
        );
        $include = './' . $def['theme path'] . '/' . $def['theme file'];
        if (file_exists($include)) {
          require_once $include;
        }
        if (!function_exists('theme_' . $def['theme'])) {
          $hooks[$def['theme']]['template'] = views_css_safe($def['theme']);
        }
      }
      if (isset($def['additional themes'])) {
        foreach ($def['additional themes'] as $theme => $theme_type) {
          if (empty($theme_type)) {
            $theme = $theme_type;
            $theme_type = $type;
          }
          $hooks[$theme] = array(
            'pattern' => $theme . '__',
            'file' => $def['theme file'],
            'path' => $def['theme path'],
            'arguments' => $arguments[$theme_type],
          );
          if (!function_exists('theme_' . $theme)) {
            $hooks[$theme]['template'] = views_css_safe($theme);
          }
        }
      }
    }
  }
  $hooks['views_exposed_form'] = $base + array(
    'template' => 'views-exposed-form',
    'pattern' => 'views_exposed_form__',
    'arguments' => array(
      'form' => NULL,
    ),
  );
  $hooks['views_more'] = $base + array(
    'template' => 'views-more',
    'pattern' => 'views_more__',
    'arguments' => array(
      'more_url' => NULL,
      'link_text' => 'more',
    ),
  );
  return $hooks;
}