You are here

public function DomainAliasUniquifier::isReserved in Domain Path 8

Checks if an alias is reserved.

Parameters

string $alias: The alias.

string $source: The source.

string $langcode: (optional) The language code.

Return value

bool Returns TRUE if the alias is reserved.

Overrides AliasUniquifier::isReserved

1 call to DomainAliasUniquifier::isReserved()
DomainAliasUniquifier::uniquify in modules/domain_path_pathauto/src/DomainAliasUniquifier.php
Check to ensure a path alias is unique and add suffix variants if necessary.

File

modules/domain_path_pathauto/src/DomainAliasUniquifier.php, line 41

Class

DomainAliasUniquifier
Provides a utility for creating a unique domain path alias.

Namespace

Drupal\domain_path_pathauto

Code

public function isReserved($alias, $source, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $domain_id = '') {

  // Check if this domain alias already exists.
  $query = \Drupal::database()
    ->select('domain_path', 'domain_path')
    ->fields('domain_path', [
    'language',
    'source',
    'alias',
  ])
    ->condition('domain_id', $domain_id)
    ->condition('alias', $alias);
  $result = $query
    ->execute()
    ->fetchAssoc();
  if (isset($result['source'])) {
    $existing_source = $result["source"];
    if ($existing_source != $alias) {

      // If it is an alias for the provided source, it is allowed to keep using
      // it. If not, then it is reserved.
      return $existing_source != $source;
    }
  }

  // Then check if there is a route with the same path.
  if ($this
    ->isRoute($alias)) {
    return TRUE;
  }

  // Finally check if any other modules have reserved the alias.
  $args = [
    $alias,
    $source,
    $langcode,
  ];
  $implementations = $this->moduleHandler
    ->getImplementations('pathauto_is_alias_reserved');
  foreach ($implementations as $module) {
    $result = $this->moduleHandler
      ->invoke($module, 'pathauto_is_alias_reserved', $args);
    if (!empty($result)) {

      // As soon as the first module says that an alias is in fact reserved,
      // then there is no point in checking the rest of the modules.
      return TRUE;
    }
  }
  return FALSE;
}