API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Path%21Al...

Enter a descriptive title (above) relating to public function AliasStorage::aliasExists, then describe the problem you have found:

Return value

bool TRUE if alias already exists and FALSE otherwise.

This is not true because the code specifically checks for NOT LIKE $source.

  if (!empty($source)) {
    $query->condition('source', $this->connection->escapeLike($source), 'NOT LIKE');
  }

Personally I think that it should check for the source as we can't check if an alias exists for a given source at the moment.

Kind regards,

Thomas Dik

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ThomasDik created an issue. See original summary.

Anonymous’s picture

Version: 8.0.x-dev » 8.4.x-dev
Component: documentation » path.module
Status: Active » Needs review
FileSize
1.12 KB
1.8 KB

We should adjust the code, not the documentation.

Status: Needs review » Needs work

The last submitted patch, 2: aliasexists_with_a-2843002-2.patch, failed testing.

jnicola’s picture

I ran into this same issue just today, and resolved it the same way that you did. So I can attest that switching from NOT LIKE to LIKE resolves the situation.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hash6’s picture

I also found an issue while creating new content, it did not check the existing aliases if langcode was set to null and was able to fix it by adding an if condition on $langcode

if ($langcode){
      $query->condition('langcode', $langcode);
}  
/**
   * {@inheritdoc}
   */
  public function aliasExists($alias, $langcode, $source = NULL) {

    // Use LIKE and NOT LIKE for case-insensitive matching.
    $query = $this->connection->select(static::TABLE)
      ->condition('alias', $this->connection->escapeLike($alias), 'LIKE');
    if ($langcode){
      $query->condition('langcode', $langcode);
    }  
    if (!empty($source)) {
      $query->condition('source', $this->connection->escapeLike($source), 'NOT LIKE');
    }
    $query->addExpression('1');
    $query->range(0, 1);
    $query_string = (string) $query;
    try {
      return (bool) $query->execute()->fetchField();
    }
    catch (\Exception $e) {
      $this->catchException($e);
      return FALSE;
    }
  }
 

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

Thanks to everyone who worked on this.

The work here relates to a change that was removed in Drupal 9.0.0 #3092090: Remove legacy Path Alias subsystem and there does not seem to be a direct replacement.

Therefore, closing as outdated.

Thanks!