function views_theme

Implement hook_theme(). Register views theming functions.

File

drupal/core/modules/views/views.module, line 82
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_theme($existing, $type, $theme, $path) {
  Drupal::moduleHandler()
    ->loadInclude('views', 'inc', 'views.theme');

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

  // Our extra version of pager from pager.inc
  $hooks['views_mini_pager'] = $base + array(
    'variables' => array(
      'tags' => array(),
      'quantity' => 10,
      'element' => 0,
      'parameters' => array(),
    ),
    'pattern' => 'views_mini_pager__',
  );
  $variables = array(
    // For displays, we pass in a dummy array as the first parameter, since
    // $view is an object but the core contextual_preprocess() function only
    // attaches contextual links when the primary theme argument is an array.
    'display' => array(
      'view_array' => array(),
      'view' => NULL,
    ),
    'style' => array(
      'view' => NULL,
      'options' => NULL,
      'rows' => NULL,
      'title' => NULL,
    ),
    'row' => array(
      'view' => NULL,
      'options' => NULL,
      'row' => NULL,
      'field_alias' => NULL,
    ),
    'exposed_form' => array(
      'view' => NULL,
      'options' => NULL,
    ),
    'pager' => array(
      'view' => NULL,
      'options' => NULL,
      'tags' => array(),
      'quantity' => 10,
      'element' => 0,
      'parameters' => array(),
    ),
  );

  // Default view themes
  $hooks['views_view_field'] = $base + array(
    'pattern' => 'views_view_field__',
    'variables' => array(
      'view' => NULL,
      'field' => NULL,
      'row' => NULL,
    ),
  );
  $hooks['views_view_grouping'] = $base + array(
    'variables' => array(
      'view' => NULL,
      'grouping' => NULL,
      'grouping_level' => NULL,
      'rows' => NULL,
      'title' => NULL,
    ),
    'template' => 'views-view-grouping',
  );
  $plugins = views_get_plugin_definitions();

  // Register theme functions for all style plugins
  foreach ($plugins as $type => $info) {
    foreach ($info as $plugin => $def) {

      // Not all plugins have theme functions, and they can also explicitly
      // prevent a theme function from being registered automatically.
      if (!isset($def['theme']) || empty($def['register_theme'])) {
        continue;
      }
      $hooks[$def['theme']] = array(
        'pattern' => $def['theme'] . '__',
        'variables' => $variables[$type],
      );
      if ($def['module'] == 'views') {
        $def['theme_file'] = 'views.theme.inc';
      }
      elseif (isset($def['theme_file'])) {
        $def['theme_path'] = drupal_get_path('module', $def['module']);
      }
      if (isset($def['theme_path'])) {
        $hooks[$def['theme']]['path'] = $def['theme_path'];
      }
      if (isset($def['theme_file'])) {
        $hooks[$def['theme']]['file'] = $def['theme_file'];
      }
      if (isset($def['theme_path']) && isset($def['theme_file'])) {
        $include = DRUPAL_ROOT . '/' . $def['theme_path'] . '/' . $def['theme_file'];
        if (is_file($include)) {
          require_once $include;
        }
      }
      if (!function_exists('theme_' . $def['theme'])) {
        $hooks[$def['theme']]['template'] = drupal_clean_css_identifier($def['theme']);
      }
    }
  }
  $hooks['views_form_views_form'] = $base + array(
    'render element' => 'form',
  );
  $hooks['views_exposed_form'] = $base + array(
    'template' => 'views-exposed-form',
    'pattern' => 'views_exposed_form__',
    'render element' => 'form',
  );
  $hooks['views_more'] = $base + array(
    'variables' => array(
      'more_url' => NULL,
      'link_text' => 'more',
      'view' => NULL,
    ),
    'template' => 'views-more',
  );
  return $hooks;
}