You are here

public function ClassShortener::shortenClass in Devel 4.x

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Helper/ClassShortener.php \Drupal\webprofiler\Helper\ClassShortener::shortenClass()
  2. 8 webprofiler/src/Helper/ClassShortener.php \Drupal\webprofiler\Helper\ClassShortener::shortenClass()
  3. 8.2 webprofiler/src/Helper/ClassShortener.php \Drupal\webprofiler\Helper\ClassShortener::shortenClass()

Parameters

string $class:

Return value

string

Overrides ClassShortenerInterface::shortenClass

File

webprofiler/src/Helper/ClassShortener.php, line 15

Class

ClassShortener
Class ClassShortener.

Namespace

Drupal\webprofiler\Helper

Code

public function shortenClass($class) {
  $parts = explode('\\', $class);
  $result = [];
  $size = count($parts) - 1;
  foreach ($parts as $key => $part) {
    if ($key < $size) {
      $result[] = substr($part, 0, 1);
    }
    else {
      $result[] = $part;
    }
  }
  return new FormattableMarkup("<abbr title=\"@class\">@short</abbr>", [
    '@class' => $class,
    '@short' => implode('\\', $result),
  ]);
}