You are here

function add_to_head_process_html in Add To Head 7

Implements hook_process_html().

This is used to inject any code onto the appropriate pages.

File

./add_to_head.module, line 94
Add To Head allows abritrary insertion of code into the head of the page based on path selection.

Code

function add_to_head_process_html(&$vars) {
  $output = array();

  // Fetch the profile information stored in the DB.
  $settings = variable_get('add_to_head_profiles', array());

  // Allow other modules to alter profile settings. Additional profiles may be added here.
  drupal_alter(basename(__FILE__, '.module') . '_profiles', $settings);

  // If applicable, append each profile's code to the output.
  foreach ($settings as $profile) {

    // Determine if the code should be visible on the current page.
    $path_visibility = isset($profile['path_visibility']) ? $profile['path_visibility'] : 0;
    $path_list = isset($profile['paths']) ? $profile['paths'] : '';
    $page_match = add_to_head_match_page($path_visibility, $path_list);

    // Determine if the code should be visible given the current user's roles.
    $role_visibility = isset($profile['roles']) && isset($profile['roles']['visibility']) ? $profile['roles']['visibility'] : 0;
    $role_list = isset($profile['roles']) && isset($profile['roles']['list']) ? $profile['roles']['list'] : array();
    $role_match = add_to_head_match_role($role_visibility, $role_list);

    // Add this profile's code if all conditions are met.
    if ($page_match && $role_match) {
      $output[] = array(
        '#markup' => $profile['code'],
        '#suffix' => "\n",
      );
    }
  }

  // If we have any output from the profiles, render it.
  if (!empty($output)) {
    $vars[$profile['scope']] .= drupal_render($output);
  }
}