You are here

function ctools_context_language_create in Chaos Tool Suite (ctools) 7

Create a context, either from manual configuration or the current language.

1 string reference to 'ctools_context_language_create'
language.inc in plugins/contexts/language.inc
Ctools context type plugin to hold the current language context.

File

plugins/contexts/language.inc, line 61
Ctools context type plugin to hold the current language context.

Code

function ctools_context_language_create($empty, $data = NULL, $conf = FALSE) {
  $context = new ctools_context('language');
  $context->plugin = 'language';
  if ($empty) {
    return $context;
  }
  $context->title = t('Language');
  $settings = ctools_context_language_conf_defaults($data);
  if ($settings['language_type'] != 'preset') {
    $language_object = $GLOBALS[$settings['language_type']];
  }
  else {

    // Fetch the enabled language objects.
    $languages = language_list('enabled');
    $languages = $languages[1];

    // Set the custom language, but fallback to the interface language.
    $language_object = $GLOBALS['language'];
    if (isset($languages[$settings['preset_langcode']])) {
      $language_object = $languages[$settings['preset_langcode']];
    }
  }

  // If enabled set the argument ot use in the cid.
  if ($settings['enable_cache_argument']) {
    $context->argument = $language_object->language;
  }
  $context->data = $language_object;
  return $context;
}