You are here

function _scald_context_fallback in Scald: Media Management made easy 6

Same name and namespace in other branches
  1. 7 scald.module \_scald_context_fallback()

Determine the next Context in the Context fallback order for this Scald Scald Unified Type.

Parameters

$type: A Scald Unified Type slug

$context: The Scald Context which is being fallen back from.

Return value

The next Scald Context in the fallback order

1 call to _scald_context_fallback()
scald_render in ./scald.module
Render a Scald Atom

File

./scald.module, line 2324

Code

function _scald_context_fallback($type, $context) {
  $scald_config = variable_get('scald_config', 0);
  $render_language = !empty($scald_config->contexts[$context]) ? $scald_config->contexts[$context]['render_language'] : 'XHTML';
  $scald_context_fallbacks = variable_get('scald_context_fallbacks', 0);

  // Generate a flat array of in-order fallback Contexts.  The highest-index
  //  Context is the most generic and least likely to fail.
  $fallbacks = array_merge(!empty($scald_context_fallbacks[$render_language][$type]) ? $scald_context_fallbacks[$render_language][$type] : array(), !empty($scald_context_fallbacks[$render_language]['@default']) ? $scald_context_fallbacks[$render_language]['@default'] : array(), $scald_context_fallbacks['@default'], array(
    'title',
  ));

  // Determine where in the order the current Context falls so that "next" has a
  //  definitive meaning.
  $current_index = array_search($context, $fallbacks);
  if (!$current_index) {
    $current_index = -1;
  }
  return $fallbacks[$current_index + 1];
}