protected function CriticalCssProvider::calculateFilePaths in Critical CSS 8
Get all possible paths to search, relatives to theme.
Return value
array Array with all possible paths.
1 call to CriticalCssProvider::calculateFilePaths()
- CriticalCssProvider::getFilePaths in src/
Asset/ CriticalCssProvider.php - Get all possible paths to search, relatives to theme.
File
- src/
Asset/ CriticalCssProvider.php, line 255
Class
- CriticalCssProvider
- Critical CSS Provider.
Namespace
Drupal\critical_css\AssetCode
protected function calculateFilePaths() {
// Opt out if module is disabled.
if (!$this
->isEnabled()) {
return [];
}
// Check if module is enabled for logged-in users.
if (!$this->currentUser
->isAnonymous() && !$this
->isEnabledForLoggedInUsers()) {
return [];
}
// Get current entity's data.
$entity = $this
->getCurrentEntity();
$entityId = NULL;
$bundleName = NULL;
if (is_object($entity) && method_exists($entity, 'id') && method_exists($entity, 'bundle')) {
$entityId = $entity
->id();
$bundleName = $entity
->bundle();
}
// Check if this entity id is excluded.
if ($entityId && $this
->isEntityIdExcluded($entityId)) {
return [];
}
// Get sanitized path, which is something like /node/{X}.
$sanitizedPath = $this
->sanitizePath($this->currentPathStack
->getPath());
// Get sanitized path info, which is something like /article/{title}.
$sanitizedPathInfo = $this
->sanitizePath($this->request
->getPathInfo());
// Get all possible paths in order, starting with the most specific ones
// (entity id) and finishing with a fallback. Between them, use a "path-"
// prefix to avoid collisions when there is a node and a bundle with the
// same name.
$filePaths[] = $this
->getFilePathByKey($entityId);
$filePaths[] = $this
->getFilePathByKey('path-' . $sanitizedPath);
$filePaths[] = $this
->getFilePathByKey($sanitizedPath);
$filePaths[] = $this
->getFilePathByKey('path-' . $sanitizedPathInfo);
$filePaths[] = $this
->getFilePathByKey($sanitizedPathInfo);
$filePaths[] = $this
->getFilePathByKey($bundleName);
$filePaths[] = $this
->getFilePathByKey('default-critical');
// Remove all null paths (if no callback is supplied to array_filter, all
// entries of array equal to FALSE are removed)
$filePaths = array_filter($filePaths);
// Remove repeated paths.
$filePaths = array_unique($filePaths);
// Allow other modules to alter file paths array.
$this->moduleHandler
->alter('critical_css_file_paths_suggestion', $filePaths, $entity);
return $filePaths;
}