Updated: Comment #0

Problem/Motivation

There are 4 path alias lookup functions in AliasManager (getSystemPath(), lookupPathSource(), getPathALias(), lookupPathAlias()), which can be partly merged and cleaned up.

We are also simplifying path alias related terminology, which should be considered while working on this ticket. See parent issue for more info about that aspect.

Proposed resolution

- merge getSystemPath() and lookupPathSource() into getPathByAlias()
- merge getPathALias() and lookupPathAlias() into getAliasByPath()

Remaining tasks

- code it
- test it

User interface changes

N/A

API changes

- getSystemPath() renamed to getPathByAlias()
- getPathALias() renamed to getAliasByPath()

Comments

slashrsm’s picture

Assigned: Unassigned » slashrsm
cs_shadow’s picture

Issue summary: View changes
slashrsm’s picture

Status: Active » Needs review
StatusFileSize
new41.98 KB

Here we go...

marcingy’s picture

Status: Needs review » Needs work
// Look for the alias within the cached map.
+    if (isset($this->lookupMap[$language]) && $path = array_search($alias, $this->lookupMap[$language])) {
+      return $path;
+    }

There should be () round the $path assignment

Need types

+   * @param $alias
+   *   An alias.
+   * @param $language

so

@param string etc.....also for return

Same for doxygen of

public function getAliasByPath($path, $language = NULL);

Over 80 characters

* Return value callback for the getAliasByPath() method on the mock alias manager

Same with

* Ensures that by default the call to getAliasByPath() will return the first argument
* that was passed in. We special-case the paths for which we wish it to return an
slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new42.21 KB
new2.71 KB

Thanks! Uploading fixed patch.

marcingy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

slashrsm’s picture

Assigned: slashrsm » Unassigned

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 5: 2233619_5.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new42.37 KB

Re-roll

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

This was a straight re-roll.

slashrsm’s picture

9: 2233619_9.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: 2233619_9.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new43.34 KB
new1000 bytes

Reroll.

marcingy’s picture

Status: Needs review » Reviewed & tested by the community

looks good

xjm’s picture

Will these change records need updates?
https://drupal.org/node/1853148
https://drupal.org/node/2221879

If so, let's update them to add a reference to this issue so that they show up in the sidebar here, and change the method names appropriately once the issue is fixed.

slashrsm’s picture

Done.

@xjm: There is also #2233623: Merge AliasManagerCacheDecorator into AliasManager in the same set, which is waiting for this to go in. Should we also add that one to same change records?

xjm’s picture

@slashrsm, good idea.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: 2233619_13.patch, failed testing.

Jalandhar’s picture

Status: Needs work » Needs review
StatusFileSize
new43.22 KB

Updating re-rolled patch.

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

This was a straight re-roll.

catch’s picture

+++ b/core/lib/Drupal/Core/Path/AliasManager.php
@@ -88,36 +88,87 @@ public function __construct(AliasStorageInterface $storage, AliasWhitelistInterf
+    // Check the path whitelist, if the top-level part before the first /

Shouldn't this happen before the pre-load of paths by language? Seems like it could avoid getting the cache entry at all in some situations.

The other changes look good.

Related is #2248897: Fix AliasManager and AliasManagerCacheDecorator, the better naming here might have avoided that bug.

xjm’s picture

Just a reminder that the change records linked in the sidebar will need updates when this goes in. Thanks!

slashrsm’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new43.22 KB
new1.42 KB
slashrsm’s picture

Status: Needs review » Needs work

The last submitted patch, 23: 2233619_23.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new42.83 KB
new2.17 KB

Status: Needs review » Needs work

The last submitted patch, 26: 2233619_26.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new43.53 KB
new754 bytes

Another function call converted.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Those changes look good, back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php
@@ -83,25 +83,25 @@ public function writeCache() {
-  public function getSystemPath($path, $path_language = NULL) {
-    $system_path = $this->aliasManager->getSystemPath($path, $path_language);
+  public function getPathByAlias($alias, $language = NULL) {
+    $path = $this->aliasManager->getPathByAlias($alias, $language);
...
-  public function getPathAlias($path, $path_language = NULL) {
-    return $this->aliasManager->getPathAlias($path, $path_language);
+  public function getAliasByPath($path, $language = NULL) {
+    return $this->aliasManager->getAliasByPath($path, $language);

+++ b/core/lib/Drupal/Core/Path/AliasManager.php
@@ -88,36 +88,87 @@ public function __construct(AliasStorageInterface $storage, AliasWhitelistInterf
-  public function getSystemPath($path, $path_language = NULL) {
+  public function getPathByAlias($alias, $language = NULL) {
     // If no language is explicitly specified we default to the current URL
     // language. If we used a language different from the one conveyed by the
     // requested URL, we might end up being unable to check if there is a path
     // alias matching the URL path.
-    $path_language = $path_language ?: $this->languageManager->getCurrentLanguage(Language::TYPE_URL)->id;
-    // Lookup the path alias first.
-    if (!empty($path) && $source = $this->lookupPathSource($path, $path_language)) {
-      $path = $source;
+    $language = $language ?: $this->languageManager->getCurrentLanguage(Language::TYPE_URL)->id;
...
-  public function getPathAlias($path, $path_language = NULL) {
+  public function getAliasByPath($path, $language = NULL) {
     // If no language is explicitly specified we default to the current URL
     // language. If we used a language different from the one conveyed by the
     // requested URL, we might end up being unable to check if there is a path
     // alias matching the URL path.
-    $path_language = $path_language ?: $this->languageManager->getCurrentLanguage(Language::TYPE_URL)->id;
-    $result = $path;
-    if (!empty($path) && $alias = $this->lookupPathAlias($path, $path_language)) {
-      $result = $alias;
+    $language = $language ?: $this->languageManager->getCurrentLanguage(Language::TYPE_URL)->id;

+++ b/core/lib/Drupal/Core/Path/AliasManagerInterface.php
@@ -10,33 +10,30 @@
+   * @param string $language
    *   An optional language code to look up the path in.
...
-  public function getSystemPath($path, $path_language = NULL);
+  public function getPathByAlias($alias, $language = NULL);
...
+   * @param string $language
    *   An optional language code to look up the path in.
...
-  public function getPathAlias($path, $path_language = NULL);
+  public function getAliasByPath($path, $language = NULL);

Since we're changing $path_language to $language let's actually pick a better name - it should be changed to $langcode since that is what it is.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new43.58 KB
new8.65 KB
slashrsm’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1299c3a and pushed to 8.x. Thanks!

diff --git a/core/lib/Drupal/Core/Path/AliasManager.php b/core/lib/Drupal/Core/Path/AliasManager.php
index f6b40ef..55d2ddc 100644
--- a/core/lib/Drupal/Core/Path/AliasManager.php
+++ b/core/lib/Drupal/Core/Path/AliasManager.php
@@ -59,7 +59,7 @@ class AliasManager implements AliasManagerInterface {
    *
    * @var array
    */
-  protected $languagePreloaded = array();
+  protected $langcodePreloaded = array();
 
   /**
    * Holds an array of previously looked up paths for the current request path.
@@ -138,8 +138,8 @@ public function getAliasByPath($path, $langcode = NULL) {
 
     // During the first call to this method per language, load the expected
     // paths for the page from cache.
-    if (empty($this->languagePreloaded[$langcode])) {
-      $this->languagePreloaded[$langcode] = TRUE;
+    if (empty($this->langcodePreloaded[$langcode])) {
+      $this->langcodePreloaded[$langcode] = TRUE;
       $this->lookupMap[$langcode] = array();
       // Load paths from cache.
       if (!empty($this->preloadedPathLookups)) {
@@ -185,7 +185,7 @@ public function cacheClear($source = NULL) {
     }
     $this->noPath = array();
     $this->noAlias = array();
-    $this->languagePreloaded = array();
+    $this->langcodePreloaded = array();
     $this->preloadedPathLookups = array();
     $this->pathAliasWhitelistRebuild($source);
   }

Renamed the languagePreloaded to langcodePreloaded

  • Commit 1299c3a on 8.x by alexpott:
    Issue #2233619 by slashrsm, Jalandhar: Merge lookup functions in...
slashrsm’s picture

slashrsm’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.