You are here

protected function EntityController::getPageArgument in Render cache 7.2

Helper function to retrieve missing $page argument from backtrace.

Return value

bool $page The page argument from entity_view() if found - NULL otherwise.

1 call to EntityController::getPageArgument()
EntityController::render in modules/controller/render_cache_entity/src/RenderCache/Controller/EntityController.php
Render uncached objects.

File

modules/controller/render_cache_entity/src/RenderCache/Controller/EntityController.php, line 123
Contains \Drupal\render_cache_entity\RenderCache\Controller\EntityController

Class

EntityController
EntityController - Provides render caching for entity objects.

Namespace

Drupal\render_cache_entity\RenderCache\Controller

Code

protected function getPageArgument() {
  $page = NULL;

  // We need the $page variable from entity_view() that it does not pass us.
  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {

    // Get only the stack frames we need (PHP 5.4 only).
    $backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
  }
  elseif (version_compare(PHP_VERSION, '5.3.6', '>=')) {
    $backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
  }
  else {

    // @see http://php.net/manual/en/function.debug-backtrace.php#refsect1-function.debug-backtrace-parameters
    $backtrace = debug_backtrace(TRUE);
  }

  // As a safety, do not grab an unexpected arg for $page, check that this
  // was called from entity_view().
  if (isset($backtrace[2]['function']) && $backtrace[2]['function'] === 'entity_view' && isset($backtrace[2]['args'][4])) {
    $page = $backtrace[2]['args'][4];
  }
  return $page;
}