private function LibraryDeprecationAnalyzer::findLibrariesAttachedInTemplate in Upgrade Status 8.3
Same name and namespace in other branches
- 8.2 src/LibraryDeprecationAnalyzer.php \Drupal\upgrade_status\LibraryDeprecationAnalyzer::findLibrariesAttachedInTemplate()
Finds libraries attached using `libraries_attach()` in a Twig template.
Parameters
\Twig\Node\Node $node:
Return value
string[]
1 call to LibraryDeprecationAnalyzer::findLibrariesAttachedInTemplate()
- LibraryDeprecationAnalyzer::analyzeTwigLibraryDependencies in src/LibraryDeprecationAnalyzer.php 
- Analyzes Twig library dependencies.
File
- src/LibraryDeprecationAnalyzer.php, line 286 
Class
- LibraryDeprecationAnalyzer
- A library deprecation analyzer.
Namespace
Drupal\upgrade_statusCode
private function findLibrariesAttachedInTemplate(Node $node) : array {
  if (!is_iterable($node)) {
    return [];
  }
  $libraries = [];
  foreach ($node as $item) {
    if ($item instanceof FunctionExpression) {
      if ($item
        ->getAttribute('name') === 'attach_library') {
        foreach ($item
          ->getNode('arguments') as $argument) {
          if ($argument instanceof ConstantExpression && $argument
            ->hasAttribute('value')) {
            $libraries[] = [
              'library' => $argument
                ->getAttribute('value'),
              'line' => $item
                ->getTemplateLine(),
            ];
          }
        }
      }
    }
    else {
      $libraries = array_merge($libraries, $this
        ->findLibrariesAttachedInTemplate($item));
    }
  }
  return $libraries;
}