private function LibraryDeprecationAnalyzer::analyzeTwigLibraryDependencies in Upgrade Status 8.2
Same name and namespace in other branches
- 8.3 src/LibraryDeprecationAnalyzer.php \Drupal\upgrade_status\LibraryDeprecationAnalyzer::analyzeTwigLibraryDependencies()
Analyzes Twig library dependencies.
At the moment we analyze only libraries attached using `library_attach()`. However, there could be other ways to attache a library in a template, such as generating and rendering a render array with `#attached`.
Parameters
\Drupal\Core\Extension\Extension $extension:
Return value
\Drupal\upgrade_status\DeprecationMessage[]
1 call to LibraryDeprecationAnalyzer::analyzeTwigLibraryDependencies()
- LibraryDeprecationAnalyzer::analyze in src/
LibraryDeprecationAnalyzer.php - Analyzes usages of deprecated libraries in an extension.
File
- src/
LibraryDeprecationAnalyzer.php, line 246
Class
- LibraryDeprecationAnalyzer
- A library deprecation analyzer.
Namespace
Drupal\upgrade_statusCode
private function analyzeTwigLibraryDependencies(Extension $extension) : array {
$iterator = new TemplateDirIterator(new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($extension
->getPath()), \RecursiveIteratorIterator::LEAVES_ONLY), '{' . preg_quote('.html.twig') . '$}'));
$deprecations = [];
foreach ($iterator as $name => $contents) {
try {
$libraries = $this
->findLibrariesAttachedInTemplate($this->twigEnvironment
->parse($this->twigEnvironment
->tokenize(new Source($contents, $name))));
foreach ($libraries as $library) {
$is_deprecated = $this
->isLibraryDeprecated($library['library']);
if (is_null($is_deprecated)) {
$message = sprintf("The '%s' library is not defined because the defining extension is not installed. Cannot decide if it is deprecated or not.", $library['library']);
$deprecations[] = new DeprecationMessage($message, $name, $library['line']);
}
elseif (!empty($is_deprecated)) {
if ($is_deprecated instanceof DeprecationMessage) {
$is_deprecated
->setFile($name);
$deprecations[] = $is_deprecated;
}
else {
$message = 'Template is attaching a deprecated library. ' . $is_deprecated;
$deprecations[] = new DeprecationMessage($message, $name, $library['line']);
}
}
}
} catch (SyntaxError $e) {
// Ignore templates containing syntax errors.
}
}
return $deprecations;
}