class LanguageNeutralAliasesStorage in Language neutral aliases 8
Language neutral alias storage.
Hierarchy
- class \Drupal\Core\Path\AliasStorage implements AliasStorageInterface
- class \Drupal\language_neutral_aliases\LanguageNeutralAliasesStorage
Expanded class hierarchy of LanguageNeutralAliasesStorage
1 file declares its use of LanguageNeutralAliasesStorage
- LanguageNeutralAliasesStorageTest.php in tests/
src/ Kernel/ LanguageNeutralAliasesStorageTest.php
File
- src/
LanguageNeutralAliasesStorage.php, line 14
Namespace
Drupal\language_neutral_aliasesView source
class LanguageNeutralAliasesStorage extends AliasStorage {
/**
* The source/path field name.
*
* @var string
*/
protected $field;
/**
* {@inheritdoc}
*/
public function __construct(Connection $connection, ModuleHandlerInterface $module_handler) {
parent::__construct($connection, $module_handler);
$this->field = 'path';
// Before 8.8 the field was named source.
if (version_compare(Drupal::VERSION, '8.8', '<')) {
$this->field = 'source';
}
}
/**
* {@inheritdoc}
*/
public function save($source, $alias, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $pid = NULL) {
// Enfoce neutral language.
$langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
// If attempting to save a non-neutral alias, save as new.
if ($pid && ($row = parent::load([
'pid' => $pid,
])) && $row && $row['langcode'] != $langcode) {
$pid = NULL;
}
return parent::save($source, $alias, $langcode, $pid);
}
/**
* {@inheritdoc}
*/
public function load($conditions) {
// Callers might have opinions about what language version they want, ignore
// them.
$conditions['langcode'] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
return parent::load($conditions);
}
/**
* {@inheritdoc}
*/
public function delete($conditions) {
$conditions['langcode'] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
return parent::delete($conditions);
}
/**
* {@inheritdoc}
*/
public function preloadPathAlias($preloaded, $langcode) {
return parent::preloadPathAlias($preloaded, LanguageInterface::LANGCODE_NOT_SPECIFIED);
}
/**
* {@inheritdoc}
*/
public function lookupPathAlias($path, $langcode) {
return parent::lookupPathAlias($path, LanguageInterface::LANGCODE_NOT_SPECIFIED);
}
/**
* {@inheritdoc}
*/
public function lookupPathSource($path, $langcode) {
return parent::lookupPathSource($path, LanguageInterface::LANGCODE_NOT_SPECIFIED);
}
/**
* {@inheritdoc}
*/
public function aliasExists($alias, $langcode, $source = NULL) {
return parent::aliasExists($alias, LanguageInterface::LANGCODE_NOT_SPECIFIED, $source);
}
/**
* {@inheritdoc}
*/
public function languageAliasExists() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getAliasesForAdminListing($header, $keys = NULL) {
$query = $this->connection
->select(static::TABLE)
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
$query
->condition('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED);
if ($keys) {
// Replace wildcards with PDO wildcards.
$query
->condition('alias', '%' . preg_replace('!\\*+!', '%', $keys) . '%', 'LIKE');
}
try {
return $query
->fields(static::TABLE)
->orderByHeader($header)
->limit(50)
->execute()
->fetchAll();
} catch (\Exception $e) {
$this
->catchException($e);
return [];
}
}
/**
* {@inheritdoc}
*/
public function pathHasMatchingAlias($initial_substring) {
$query = $this->connection
->select(static::TABLE, 'u');
$query
->addExpression(1);
try {
return (bool) $query
->condition('u.' . $this->field, $this->connection
->escapeLike($initial_substring) . '%', 'LIKE')
->condition('u.langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED)
->range(0, 1)
->execute()
->fetchField();
} catch (\Exception $e) {
$this
->catchException($e);
return FALSE;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AliasStorage:: |
protected | property | The database connection. | |
AliasStorage:: |
protected | property | The entity type manager. | |
AliasStorage:: |
protected | property | The module handler. | |
AliasStorage:: |
protected | function | Adds path alias language fallback conditions to a select query object. | |
AliasStorage:: |
protected | function | Returns a SELECT query for the path_alias base table. | |
AliasStorage:: |
protected | function | Returns the path alias entity storage handler. | |
AliasStorage:: |
constant | The table for the url_alias storage. | ||
LanguageNeutralAliasesStorage:: |
protected | property | The source/path field name. | |
LanguageNeutralAliasesStorage:: |
public | function |
Checks if alias already exists. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Deletes a URL alias. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Loads aliases for admin listing. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Checks if there are any aliases with language defined. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Fetches a specific URL alias from the database. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Returns an alias of Drupal system URL. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Returns Drupal system URL of an alias. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Check if any alias exists starting with $initial_substring. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Pre-loads path alias information for a given list of source paths. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Saves a path alias to the database. Overrides AliasStorage:: |
|
LanguageNeutralAliasesStorage:: |
public | function |
Constructs a Path CRUD object. Overrides AliasStorage:: |