Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ThemeSniff.php

function ThemeSniff::process

Processes this function call.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the function call in: the stack.

Return value

void

Overrides FunctionCall::process

File

vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php, line 49

Class

ThemeSniff
\DrupalPractice\Sniffs\FunctionCalls\Checks that theme functions are not directly called.

Namespace

DrupalPractice\Sniffs\FunctionCalls

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $functionName = $tokens[$stackPtr]['content'];
    if (strpos($functionName, 'theme_') !== 0 || in_array($functionName, $this->reservedFunctions) === true || $this->isFunctionCall($phpcsFile, $stackPtr) === false) {
        return;
    }
    $themeName = substr($functionName, 6);
    $warning = "Do not call theme functions directly, use theme('%s', ...) instead";
    $phpcsFile->addWarning($warning, $stackPtr, 'ThemeFunctionDirect', [
        $themeName,
    ]);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal