Returns a listing of all defined URL aliases.
When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.
function path_admin_overview($keys = NULL) {
// Add the filter form above the overview table.
$build['path_admin_filter_form'] = drupal_get_form('path_admin_filter_form', $keys);
// Enable language column if language.module is enabled or if we have any
// alias with a language.
$alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE langcode <> :langcode', 0, 1, array(
':langcode' => Language::LANGCODE_NOT_SPECIFIED,
))
->fetchField();
$multilanguage = module_exists('language') || $alias_exists;
$header = array();
$header[] = array(
'data' => t('Alias'),
'field' => 'alias',
'sort' => 'asc',
);
$header[] = array(
'data' => t('System'),
'field' => 'source',
);
if ($multilanguage) {
$header[] = array(
'data' => t('Language'),
'field' => 'langcode',
);
}
$header[] = t('Operations');
$query = db_select('url_alias')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
if ($keys) {
// Replace wildcards with PDO wildcards.
$query
->condition('alias', '%' . preg_replace('!\\*+!', '%', $keys) . '%', 'LIKE');
}
$result = $query
->fields('url_alias')
->orderByHeader($header)
->limit(50)
->execute();
$rows = array();
$destination = drupal_get_destination();
foreach ($result as $data) {
$row = array();
$row['data']['alias'] = l(truncate_utf8($data->alias, 50, FALSE, TRUE), $data->source, array(
'attributes' => array(
'title' => $data->alias,
),
));
$row['data']['source'] = l(truncate_utf8($data->source, 50, FALSE, TRUE), $data->source, array(
'alias' => TRUE,
'attributes' => array(
'title' => $data->source,
),
));
if ($multilanguage) {
$row['data']['language_name'] = language_name($data->langcode);
}
$operations = array();
$operations['edit'] = array(
'title' => t('edit'),
'href' => "admin/config/search/path/edit/{$data->pid}",
'query' => $destination,
);
$operations['delete'] = array(
'title' => t('delete'),
'href' => "admin/config/search/path/delete/{$data->pid}",
'query' => $destination,
);
$row['data']['operations'] = array(
'data' => array(
'#type' => 'operations',
'#links' => $operations,
),
);
// If the system path maps to a different URL alias, highlight this table
// row to let the user know of old aliases.
if ($data->alias != drupal_container()
->get('path.alias_manager')
->getPathAlias($data->source, $data->langcode)) {
$row['class'] = array(
'warning',
);
}
$rows[] = $row;
}
$build['path_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No URL aliases available. <a href="@link">Add URL alias</a>.', array(
'@link' => url('admin/config/search/path/add'),
)),
);
$build['path_pager'] = array(
'#theme' => 'pager',
);
return $build;
}