function IconFinder::extractIconIdFromFilename

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Theme/Icon/IconFinder.php \Drupal\Core\Theme\Icon\IconFinder::extractIconIdFromFilename()

Check if {icon_id} is a part of the name and need to be extracted.

Parameters

string $filename: The filename found to match against.

string $filename_pattern: The path with {icon_id}.

Return value

string The extracted icon ID or the original filename.

1 call to IconFinder::extractIconIdFromFilename()
IconFinder::processFoundFiles in core/lib/Drupal/Core/Theme/Icon/IconFinder.php
Process files and format icon information.

File

core/lib/Drupal/Core/Theme/Icon/IconFinder.php, line 331

Class

IconFinder
Icon finder to discover files under specific paths or URLs.

Namespace

Drupal\Core\Theme\Icon

Code

private static function extractIconIdFromFilename(string $filename, string $filename_pattern) : string {
  $pattern = str_replace(self::ICON_ID_PATTERN, '(?<icon_id>.+)?', $filename_pattern);
  if (preg_match('@' . $pattern . '@', $filename, $matches)) {
    return $matches['icon_id'] ?? $filename;
  }
  return $filename;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.