You are here

public function RenameAdminPathsProcessor::processInbound in Rename Admin Paths 8

Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processInbound().

Overrides InboundPathProcessorInterface::processInbound

File

src/RenameAdminPathsProcessor.php, line 18

Class

RenameAdminPathsProcessor
Path processor for url_alter_test.

Namespace

Drupal\rename_admin_paths

Code

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;
}