statistics.php

Same filename in other branches
  1. 7.x modules/statistics/statistics.php
  2. 8.9.x core/modules/statistics/statistics.php
  3. 10 core/modules/statistics/statistics.php
  4. 11.x core/modules/statistics/statistics.php

Handles counts of node views via AJAX with minimal bootstrap.

File

core/modules/statistics/statistics.php

View source
<?php


/**
 * @file
 * Handles counts of node views via AJAX with minimal bootstrap.
 */
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
chdir('../../..');
$autoloader = (require_once 'autoload.php');
$kernel = DrupalKernel::createFromRequest(Request::createFromGlobals(), $autoloader, 'prod');
$kernel->boot();
$container = $kernel->getContainer();
$views = $container->get('config.factory')
    ->get('statistics.settings')
    ->get('count_content_views');
if ($views) {
    $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT);
    if ($nid) {
        $container->get('request_stack')
            ->push(Request::createFromGlobals());
        $container->get('statistics.storage.node')
            ->recordView($nid);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.