You are here

function site_banner_generate_context_banner_text_from_contexts in Site Banner 7

Returns new banner text by collapsing all active contexts into string.

Parameters

array $contexts: the context array.

string $banner_text: the existing banner text

Return value

string the updated banner text via $banner_text

2 calls to site_banner_generate_context_banner_text_from_contexts()
SiteBannerContextReactionChangeBannerText::execute in ./site_banner_context_reaction_functions.inc
Output banner text for active contexts.
SiteBannerRenderingUnitTestCase::testBannerContextTextChange in ./site_banner.test
Tests whether multiple contexts changing a banner text is properly handled.

File

./site_banner.module, line 343
Main module file implementing callbacks for the site banner module.

Code

function site_banner_generate_context_banner_text_from_contexts($contexts, &$banner_text) {
  $site_banner_array = array();
  $banner_active = variable_get('site_banner_status', FALSE);
  $debug_mode = site_banner_check_if_debug_mode_active();
  if (module_exists('context')) {
    $plugin = context_get_plugin('reaction', 'change_banner_status');
    if ($plugin) {
      $plugin
        ->execute($banner_active, $debug_mode);
    }
  }
  foreach ($contexts as $context) {
    if (!empty($context->reactions['change_banner_text'])) {
      $new_banner_context = $context->reactions['change_banner_text'];
      if (!empty($new_banner_context)) {
        $context_tag = $context->tag;
        if (!array_key_exists($context_tag, $site_banner_array)) {

          // Tag does not exist - populate with initial values.
          $site_banner_array[$context_tag]['prepend_text'] = $new_banner_context['site_banner_tag_prepend_text'];
          $site_banner_array[$context_tag]['delimiter_text'] = $new_banner_context['site_banner_tag_delimiter_text'];
          $site_banner_array[$context_tag]['append_text'] = $new_banner_context['site_banner_tag_append_text'];
          $site_banner_array[$context_tag]['banner_text'] = array();
        }
        else {
          site_banner_verify_banner_text($site_banner_array, $new_banner_context, 'prepend_text', 'site_banner_tag_prepend_text', $context->name, $context_tag, 'prepended banner text');
          site_banner_verify_banner_text($site_banner_array, $new_banner_context, 'delimiter_text', 'site_banner_tag_delimiter_text', $context->name, $context_tag, 'delimiter banner text');
          site_banner_verify_banner_text($site_banner_array, $new_banner_context, 'append_text', 'site_banner_tag_append_text', $context->name, $context_tag, 'appended banner text');
        }
        array_push($site_banner_array[$context_tag]['banner_text'], $new_banner_context['site_banner_text']);
      }
    }
  }
  if (!empty($site_banner_array)) {
    $outer_first = TRUE;
    $new_site_banner = '';
    foreach ($site_banner_array as $site_banner_entry) {
      if ($outer_first) {
        $outer_first = FALSE;
      }
      else {

        // As not the first time printing a banner entry,
        // add a blank space to separate successive context entries.
        $new_site_banner .= ' ';
      }
      $new_site_banner .= $site_banner_entry['prepend_text'];
      $inner_first = TRUE;
      foreach ($site_banner_entry['banner_text'] as $site_banner_text_entries) {
        if ($inner_first) {
          $inner_first = FALSE;
        }
        else {

          // As not the first time printing a delimited banner entry,
          // add a delimiter to separate successive context entries.
          $new_site_banner .= $site_banner_entry['delimiter_text'];
        }
        $new_site_banner .= $site_banner_text_entries;
      }
      $new_site_banner .= $site_banner_entry['append_text'];
    }
    $banner_text = $new_site_banner;
  }
  if (!empty($context) && $debug_mode) {
    $banner_text = site_banner_generate_link_to_admin_page($banner_text);
    $banner_text .= ' (Active contexts: ';
    foreach ($contexts as $context) {
      $banner_text .= l($context->name, 'admin/structure/context/list/' . $context->name);
      if (!($context === end($contexts))) {
        $banner_text .= ', ';
      }
    }
    $banner_text .= ')';
  }
}