3 namespace Drupal\path\Controller;
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Controller\ControllerBase;
7 use Drupal\Core\Path\AliasStorageInterface;
8 use Drupal\Core\Path\AliasManagerInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11 use Symfony\Component\HttpFoundation\Request;
14 * Controller routines for path routes.
16 class PathController extends ControllerBase {
19 * The path alias storage.
21 * @var \Drupal\Core\Path\AliasStorageInterface
23 protected $aliasStorage;
26 * The path alias manager.
28 * @var \Drupal\Core\Path\AliasManagerInterface
30 protected $aliasManager;
33 * Constructs a new PathController.
35 * @param \Drupal\Core\Path\AliasStorageInterface $alias_storage
36 * The path alias storage.
37 * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
38 * The path alias manager.
40 public function __construct(AliasStorageInterface $alias_storage, AliasManagerInterface $alias_manager) {
41 $this->aliasStorage = $alias_storage;
42 $this->aliasManager = $alias_manager;
48 public static function create(ContainerInterface $container) {
50 $container->get('path.alias_storage'),
51 $container->get('path.alias_manager')
56 * Displays the path administration overview page.
58 * @param \Symfony\Component\HttpFoundation\Request $request
62 * A render array as expected by
63 * \Drupal\Core\Render\RendererInterface::render().
65 public function adminOverview(Request $request) {
66 $keys = $request->query->get('search');
67 // Add the filter form above the overview table.
68 $build['path_admin_filter_form'] = $this->formBuilder()->getForm('Drupal\path\Form\PathFilterForm', $keys);
69 // Enable language column if language.module is enabled or if we have any
70 // alias with a language.
71 $multilanguage = ($this->moduleHandler()->moduleExists('language') || $this->aliasStorage->languageAliasExists());
74 $header[] = ['data' => $this->t('Alias'), 'field' => 'alias', 'sort' => 'asc'];
75 $header[] = ['data' => $this->t('System'), 'field' => 'source'];
77 $header[] = ['data' => $this->t('Language'), 'field' => 'langcode'];
79 $header[] = $this->t('Operations');
82 $destination = $this->getDestinationArray();
83 foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
85 // @todo Should Path module store leading slashes? See
86 // https://www.drupal.org/node/2430593.
87 $row['data']['alias'] = $this->l(Unicode::truncate($data->alias, 50, FALSE, TRUE), Url::fromUserInput($data->source, [
88 'attributes' => ['title' => $data->alias],
90 $row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUserInput($data->source, [
92 'attributes' => ['title' => $data->source],
95 $row['data']['language_name'] = $this->languageManager()->getLanguageName($data->langcode);
99 $operations['edit'] = [
100 'title' => $this->t('Edit'),
101 'url' => Url::fromRoute('path.admin_edit', ['pid' => $data->pid], ['query' => $destination]),
103 $operations['delete'] = [
104 'title' => $this->t('Delete'),
105 'url' => Url::fromRoute('path.delete', ['pid' => $data->pid], ['query' => $destination]),
107 $row['data']['operations'] = [
109 '#type' => 'operations',
110 '#links' => $operations,
114 // If the system path maps to a different URL alias, highlight this table
115 // row to let the user know of old aliases.
116 if ($data->alias != $this->aliasManager->getAliasByPath($data->source, $data->langcode)) {
117 $row['class'] = ['warning'];
123 $build['path_table'] = [
125 '#header' => $header,
127 '#empty' => $this->t('No URL aliases available. <a href=":link">Add URL alias</a>.', [':link' => $this->url('path.admin_add')]),
129 $build['path_pager'] = ['#type' => 'pager'];