You are here

function google_appliance_block_view_alter in Google Search Appliance 7

Implements hook_block_view_alter().

This function is used to hide user-specified blocks from the crawler by wrapping them in google on/off tags.

See also

google_appliance_form_block_admin_configure_alter()

_google_appliance_get_googleonoff()

https://developers.google.com/search-appliance/documentation/64/admin_cr...

File

./google_appliance.module, line 369
Google Appliance module enables searching via a dedicated Google Search Appliance hardware device. See README.txt and the help page at admin/help/google_appliance.

Code

function google_appliance_block_view_alter(&$data, $block) {
  $settings = _google_appliance_get_settings();
  $module = $block->module;
  $delta = $block->delta;

  // Only wrap specified blocks.
  if (isset($settings['block_visibility_settings'][$module][$delta])) {
    $tags = _google_appliance_get_googleonoff();
    $tag_type = $settings['block_visibility_settings'][$module][$delta];
    $prefix = $tags[$tag_type]['prefix'];
    $suffix = $tags[$tag_type]['suffix'];

    // Sanity check to make sure we have a valid block.
    if (isset($data['content'])) {

      // We may be dealing with either a string of HTML or a renderable array.
      if (is_array($data['content'])) {

        // Special case if there's already markup.
        if (isset($data['content']['#markup'])) {
          $data['content']['#markup'] = $prefix . $data['content']['#markup'] . $suffix;
        }
        else {
          if (isset($data['content']['#prefix'])) {
            $data['content']['#prefix'] = $prefix . $data['content']['#prefix'];
          }
          else {
            $data['content']['#prefix'] = $prefix;
          }
          if (isset($data['content']['#suffix'])) {
            $data['content']['#suffix'] .= $suffix;
          }
          else {
            $data['content']['#suffix'] = $suffix;
          }
        }
      }
      else {
        $data['content'] = $prefix . $data['content'] . $suffix;
      }
    }
  }
}