You are here

function restrict_ip_preprocess_page in Restrict IP 8

Same name and namespace in other branches
  1. 8.2 restrict_ip.module \restrict_ip_preprocess_page()
  2. 6 restrict_ip.module \restrict_ip_preprocess_page()
  3. 7.2 restrict_ip.module \restrict_ip_preprocess_page()
  4. 7 restrict_ip.module \restrict_ip_preprocess_page()
  5. 3.x restrict_ip.module \restrict_ip_preprocess_page()

Override of template_preprocess_page()

This function unsets tabs and various other page elements for blocked users so they are not rendered

File

./restrict_ip.module, line 37

Code

function restrict_ip_preprocess_page(&$build) {
  if (\Drupal::service('restrict_ip.service')
    ->userIsBlocked()) {
    $regions = system_region_list(\Drupal::service('theme.manager')
      ->getActiveTheme()
      ->getName(), REGIONS_ALL);
    unset($regions['content']);
    $whitelisted_regions = Drupal::service('module_handler')
      ->invokeAll('restrict_ip_whitelisted_regions');
    foreach ($whitelisted_regions as $wr) {
      unset($regions[$wr]);
    }
    foreach (array_keys($regions) as $region) {
      if (isset($build['page'][$region])) {
        unset($build['page'][$region]);
      }
    }
    if (isset($build['tabs'])) {
      if (isset($build['tabs']['#primary'])) {
        $build['tabs']['#primary'] = [];
      }
      if (isset($build['tabs']['#secondary'])) {
        $build['tabs']['#primary'] = [];
      }
    }
    $build['title_prefix'] = [];
    $build['title_suffix'] = [];
    $build['main_menu'] = [];
    $build['secondary_menu'] = [];
    $build['action_links'] = [];
  }
}