You are here

function _scald_context_fallback in Scald: Media Management made easy 7

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

Determine the next Context in the Context fallback order for this type.

@codingStandardsIgnoreStart

Parameters

string $type: A Scald Unified Type slug.

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

Return value

string 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 1507
The Scald Core, which handles all Scald Registries and dispatch.

Code

function _scald_context_fallback($type, $context) {

  // @codingStandardsIgnoreEnd
  $contexts = scald_contexts();
  $render_language = !empty($contexts[$context]) ? $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. Ending the array
  // with the 'title' context thus ensures that the recursion will end.
  $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 === FALSE) {
    $current_index = -1;
  }
  return $fallbacks[$current_index + 1];
}