You are here

function search_by_page_page_content in Search by Page 8

Same name and namespace in other branches
  1. 7 search_by_page.module \search_by_page_page_content()

Returns the content portion of the rendered page at the given path.

Note: As a side effect, theme, pager, and page title variables may be altered. The calling function needs to make sure they are restored. Do not call this during rendering of search results! Use search_by_page_stored_page_content() instead.

Parameters

$path: Path to render.

Return value

An integer error code if there is a problem. A string containing the page content if all is well.

1 call to search_by_page_page_content()
search_by_page_update_index in ./search_by_page.module
Implements hook_update_index().

File

./search_by_page.module, line 252
Main module file for Drupal module Search by Page.

Code

function search_by_page_page_content($path) {
  $save_get = $_GET;
  $save_content = drupal_set_page_content();

  // Separate path into main part and query.
  $parts = \Drupal::service('search_by_page.settings')
    ->explodePathParts($path);
  $path = drupal_get_normal_path($parts[0]);
  $_GET['q'] = $path;

  // Add query to $_GET as it would be on a page request.
  if (isset($parts[1])) {
    $getstuff = [];
    parse_str($parts[1], $getstuff);
    $_GET += $getstuff;
  }

  // Set up the theme and get page information.
  drupal_static_reset('menu_get_item');
  _search_by_page_setup_theme();
  $page = menu_execute_active_handler($path, FALSE);
  if (is_int($page)) {

    // Error code return.
    $_GET = $save_get;
    drupal_set_page_content($save_content);
    drupal_static('system_main_content_added', FALSE);
    return $page;
  }

  // If we get here, we'll follow what \Drupal::service('renderer')->render_page does to let
  // other modules alter the page.
  if (is_string($page) || is_array($page) && (!isset($page['#type']) || $page['#type'] != 'page')) {
    drupal_set_page_content($page);
    $page = element_info('page');
  }
  foreach (module_implements('page_build') as $module) {
    $function = $module == 'block' ? '_search_by_page_build_content_blocks' : $module . '_page_build';
    $function($page);
  }
  drupal_alter('page', $page);
  if (!isset($page['content'])) {
    $page['content']['system_main'] = drupal_set_page_content();
  }
  $content = \Drupal::service('renderer')
    ->render($page['content']);
  $_GET = $save_get;
  drupal_set_page_content($save_content);
  drupal_static('system_main_content_added', FALSE);
  drupal_static_reset('menu_tree_set_path');
  drupal_static_reset('menu_tree_page_data');
  drupal_static_reset('menu_get_item');
  return $content;
}