public function AliasStorage::aliasExists in Multiversion 8
Checks if alias already exists.
The default implementation performs case-insensitive matching on the 'source' and 'alias' strings.
Parameters
string $alias: Alias to check against.
string $langcode: Language of the alias.
string|null $source: (optional) Path that alias is to be assigned to.
Return value
bool TRUE if alias already exists and FALSE otherwise.
Overrides AliasStorage::aliasExists
File
- src/
AliasStorage.php, line 276
Class
- AliasStorage
- Extends the core AliasStore class. We need this to make possible aliases to work with Multiversion and Replication.
Namespace
Drupal\multiversionCode
public function aliasExists($alias, $langcode, $source = NULL) {
if (!$this->connection
->schema()
->fieldExists('url_alias', 'workspace')) {
return parent::aliasExists($alias, $langcode, $source);
}
// Use LIKE and NOT LIKE for case-insensitive matching.
$query = $this->connection
->select(static::TABLE)
->condition('alias', $this->connection
->escapeLike($alias), 'LIKE')
->condition('langcode', $langcode)
->condition('workspace', [
$this->workspaceManager
->getActiveWorkspaceId(),
0,
], 'IN');
if (!empty($source)) {
$query
->condition('source', $this->connection
->escapeLike($source), 'NOT LIKE');
}
$query
->addExpression('1');
$query
->range(0, 1);
try {
return (bool) $query
->execute()
->fetchField();
} catch (\Exception $e) {
$this
->catchException($e);
return FALSE;
}
}