diff --git a/src/Formatter.php b/src/Formatter.php
index da6bfd93e810bba9cc05f08ae8e18c9defdaec8c..a14958800e8991ccc784df284f69db4ff96365c6 100644
--- a/src/Formatter.php
+++ b/src/Formatter.php
@@ -740,6 +740,28 @@ class Formatter {
return $text;
}
+ /**
+ * Mark the keys of service aliases for linking.
+ *
+ * @param string $code
+ * The source of a services YAML file.
+ * @param array $parsed
+ * The parsed array of the same.
+ *
+ * @return string
+ * The source with the service aliases marked with appropriate HTML for
+ * linking.
+ */
+ public static function linkServiceAliasKeys(string $code, array $parsed): string {
+ $replace = [];
+ foreach ($parsed['services'] ?? [] as $name => $info) {
+ if (is_string($info)) {
+ $replace["$name:"] = '<span class="php-function-or-constant">' . $name . '</span>:';
+ }
+ }
+ return strtr($code, $replace);
+ }
+
/**
* Turns function, class, and other names into links in documentation.
*
diff --git a/src/Parser.php b/src/Parser.php
index 9169344e59d02ef7c845f077cc30942fc6134e53..81503a3dff4fe1b4447c2d5a308256c477ac7f30 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -872,6 +872,9 @@ class Parser {
$code = Formatter::numberLines($code);
$code = Formatter::wrapPhpCode($code);
$code = Formatter::validateEncoding($code);
+ if ($is_services) {
+ $code = Formatter::linkServiceAliasKeys($code, $parsed);
+ }
$docblock['code'] = $code;
$full_references = $references;
diff --git a/tests/files/special_files/StorageCacheInterface.php b/tests/files/special_files/StorageCacheInterface.php
new file mode 100644
index 0000000000000000000000000000000000000000..e402ecc98e6466ac6ab496d8a7a125fa2a7dfba8
--- /dev/null
+++ b/tests/files/special_files/StorageCacheInterface.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Drupal\Core\Config;
+
+/**
+ * Defines an interface for cached configuration storage.
+ */
+interface StorageCacheInterface {
+
+ /**
+ * Reset the static cache of the listAll() cache.
+ */
+ public function resetListCache();
+
+}
diff --git a/tests/src/Functional/SpecialIssuesTest.php b/tests/src/Functional/SpecialIssuesTest.php
index 972dd053a393fc0f529d4c8bca36702ad6acb5df..a3140423c48d5fd7598375d2d5a8edb80b9195a9 100644
--- a/tests/src/Functional/SpecialIssuesTest.php
+++ b/tests/src/Functional/SpecialIssuesTest.php
@@ -48,6 +48,7 @@ class SpecialIssuesTest extends WebPagesBase {
$this->verifyParseAlterHook();
$this->verifyReferences();
$this->verifySearchCaseSensitivity();
+ $this->verifyLinkServiceAliasKeys();
}
/**
@@ -306,4 +307,12 @@ class SpecialIssuesTest extends WebPagesBase {
}
}
+ /**
+ * Verifies the keys of service aliases are linked.
+ */
+ protected function verifyLinkServiceAliasKeys() {
+ $this->drupalGet('api/' . $this->branchInfo['project'] . '/test.services.yml/6');
+ $this->assertSession()->linkExists('Drupal\Core\Config\StorageCacheInterface');
+ }
+
}