DomainAliasUniquifier.php in Domain Path 8
File
modules/domain_path_pathauto/src/DomainAliasUniquifier.php
View source
<?php
namespace Drupal\domain_path_pathauto;
use Drupal\Core\Language\LanguageInterface;
use Drupal\pathauto\AliasUniquifier;
use Drupal\Component\Utility\Unicode;
class DomainAliasUniquifier extends AliasUniquifier {
public function uniquify(&$alias, $source, $langcode, $domain_id = '') {
$config = $this->configFactory
->get('pathauto.settings');
if (!$this
->isReserved($alias, $source, $langcode, $domain_id)) {
return;
}
$maxlength = min($config
->get('max_length'), $this->aliasStorageHelper
->getAliasSchemaMaxlength());
$separator = $config
->get('separator');
$original_alias = $alias;
$i = 0;
do {
$unique_suffix = $separator . $i;
$alias = Unicode::truncate($original_alias, $maxlength - mb_strlen($unique_suffix), TRUE) . $unique_suffix;
$i++;
} while ($this
->isReserved($alias, $source, $langcode));
}
public function isReserved($alias, $source, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $domain_id = '') {
$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) {
return $existing_source != $source;
}
}
if ($this
->isRoute($alias)) {
return TRUE;
}
$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)) {
return TRUE;
}
}
return FALSE;
}
}