You are here

i18n_page_views.module in i18n page views 6

Same filename and directory in other branches
  1. 6.0 i18n_page_views.module
  2. 7 i18n_page_views.module

File

i18n_page_views.module
View source
<?php

/**
 * Implementation of hook_views_api().
 */
function i18n_page_views_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'i18n_page_views') . '/includes',
  );
}
function i18n_page_views_views_pre_build(&$view) {

  //Is a i18n_page, but don't use that code if it is a live preview, because in live preview the module work like a charm
  if (strstr($view->current_display, 'i18n_page') && !$view->preview) {
    global $language;

    //Get arguments via url, including display path
    $arg = arg();
    $views_args = array();

    //Separate each argument (form url) knowing the language path for this display
    $path = explode('/', $view->display[$view->current_display]->display_options['path_' . $language->language]);

    //Search real arguments to set view arguments
    foreach ($path as $pos => $unit) {
      if ($unit == '%') {
        $view_args[] = $arg[$pos];
      }
    }
    $view->args = $view_args;
  }
}

/**
 * Implements hook_context_plugins().
 *
 * Register our context plugins.
 */
function i18n_page_views_context_plugins() {
  $plugins = array();
  $plugins['context_condition_i18n_views'] = array(
    'handler' => array(
      'path' => drupal_get_path('module', 'i18n_page_views'),
      'file' => 'context_condition_i18n_views.inc',
      'class' => 'context_condition_i18n_views',
      'parent' => 'context_condition',
    ),
  );
  return $plugins;
}

/**
 * Implements hook_context_registry().
 *
 * Provice a context condition plugin for i18n_page views.
 */
function i18n_page_views_context_registry() {
  return array(
    'conditions' => array(
      'context_condition_i18n_views' => array(
        'title' => t('i18n Views'),
        'plugin' => 'context_condition_i18n_views',
        'description' => t('Set this context when displaying the page of one of these i18n views.'),
      ),
    ),
  );
}

/**
 * Implementation of hook_views_pre_view().
 */
function i18n_page_views_views_pre_view($view, $args) {
  if (module_exists('context')) {
    if ($plugin = context_get_plugin('condition', 'context_condition_i18n_views')) {
      $plugin
        ->execute($view);
    }
  }
}