class RenameAdminPathsProcessor in Rename Admin Paths 8
Path processor for url_alter_test.
Hierarchy
- class \Drupal\rename_admin_paths\RenameAdminPathsProcessor implements InboundPathProcessorInterface, OutboundPathProcessorInterface
Expanded class hierarchy of RenameAdminPathsProcessor
1 string reference to 'RenameAdminPathsProcessor'
1 service uses RenameAdminPathsProcessor
File
- src/
RenameAdminPathsProcessor.php, line 13
Namespace
Drupal\rename_admin_pathsView source
class RenameAdminPathsProcessor implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
/**
* Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processInbound().
*/
public function processInbound($path, Request $request) {
$config = \Drupal::config('rename_admin_paths.settings');
// Admin path.
if ($config
->get('admin_path')) {
$admin_path_value = $config
->get('admin_path_value');
// 404 for default admin path.
if (preg_match('|^/admin(?![^/])|i', $path)) {
$path = '/404';
}
elseif (preg_match('|^/' . urlencode($admin_path_value) . '(?![^/])(.*)|', $path, $matches)) {
$path = '/admin' . $matches[1];
}
}
// User path.
if ($config
->get('user_path')) {
$user_path_value = $config
->get('user_path_value');
// 404 for default user path.
if (preg_match('|^/user(?![^/])|i', $path)) {
$path = '/404';
}
elseif (preg_match('|^/' . urlencode($user_path_value) . '(?![^/])(.*)|', $path, $matches)) {
$path = '/user' . $matches[1];
}
}
return $path;
}
/**
* Implements Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound().
*/
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
$config = \Drupal::config('rename_admin_paths.settings');
// Admin path.
if ($request && $config
->get('admin_path')) {
$admin_path_value = $config
->get('admin_path_value');
// Replace admin in path.
if (preg_match('|^/admin(?![^/])(.*)|', $path, $matches)) {
$path = '/' . urlencode($admin_path_value) . $matches[1];
}
}
// User path.
if ($config
->get('user_path')) {
$user_path_value = $config
->get('user_path_value');
// Replace user in path.
if (preg_match('|^/user(?![^/])(.*)|', $path, $matches)) {
$path = '/' . urlencode($user_path_value) . $matches[1];
}
}
return $path;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RenameAdminPathsProcessor:: |
public | function |
Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processInbound(). Overrides InboundPathProcessorInterface:: |
|
RenameAdminPathsProcessor:: |
public | function |
Implements Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound(). Overrides OutboundPathProcessorInterface:: |