public function ThemeFunctionDeprecationAnalyzer::analyze in Upgrade Status 8.2
Same name and namespace in other branches
- 8.3 src/ThemeFunctionDeprecationAnalyzer.php \Drupal\upgrade_status\ThemeFunctionDeprecationAnalyzer::analyze()
Analyzes theme functions in an extension.
Parameters
\Drupal\Core\Extension\Extension $extension: The extension to be analyzed.
Return value
\Drupal\upgrade_status\DeprecationMessage[]
File
- src/
ThemeFunctionDeprecationAnalyzer.php, line 51
Class
- ThemeFunctionDeprecationAnalyzer
- A theme function deprecation analyzer.
Namespace
Drupal\upgrade_statusCode
public function analyze(Extension $extension) : array {
$deprecation_messages = [];
// Analyze hook_theme and hook_theme_registry_alter functions.
$deprecation_messages = array_merge($deprecation_messages, $this
->analyzeFunction($extension
->getName() . '_' . 'theme', $extension));
$deprecation_messages = array_merge($deprecation_messages, $this
->analyzeFunction($extension
->getName() . '_' . 'theme_registry_alter', $extension));
// If a theme is being analyzed, theme function overrides need to be
// analyzed.
if ($extension
->getType() === 'theme') {
// Create new instance of theme registry to ensure that we have the most
// recent data without having to make changes to the production theme
// registry.
$theme_registry = new Registry($this->container
->get('app.root'), new NullBackend('null'), $this->container
->get('lock'), $this->container
->get('module_handler'), $this->container
->get('theme_handler'), $this->container
->get('theme.initialization'), $extension
->getName());
$theme_registry
->setThemeManager($this->container
->get('theme.manager'));
$theme_hooks = $theme_registry
->get();
$theme_function_overrides = drupal_find_theme_functions($theme_hooks, [
$extension
->getName(),
]);
foreach ($theme_function_overrides as $machine_name => $theme_function_override) {
try {
$function = new \ReflectionFunction($extension
->getName() . '_' . $machine_name);
$file = $function
->getFileName();
$line = $function
->getStartLine();
$deprecation_messages[$extension
->getName() . '_' . $machine_name] = new DeprecationMessage(sprintf('The theme is overriding the "%s" theme function. Theme functions are deprecated. For more info, see https://www.drupal.org/node/2575445.', $machine_name), $file, $line);
} catch (\ReflectionException $e) {
// This should never happen because drupal_find_theme_functions()
// ensures that the function exists.
}
}
}
return $deprecation_messages;
}