You are here

function xmlsitemap_custom_list_links in XML sitemap 7.2

Same name and namespace in other branches
  1. 6.2 xmlsitemap_custom/xmlsitemap_custom.admin.inc \xmlsitemap_custom_list_links()

List Links.

1 string reference to 'xmlsitemap_custom_list_links'
xmlsitemap_custom_menu in xmlsitemap_custom/xmlsitemap_custom.module
Implements hook_menu().

File

xmlsitemap_custom/xmlsitemap_custom.admin.inc, line 11
Administrative page callbacks for the xmlsitemap_custom.

Code

function xmlsitemap_custom_list_links() {
  $header = array(
    'loc' => array(
      'data' => t('Location'),
      'field' => 'loc',
      'sort' => 'asc',
    ),
    'priority' => array(
      'data' => t('Priority'),
      'field' => 'priority',
    ),
    'changefreq' => array(
      'data' => t('Change frequency'),
      'field' => 'changefreq',
    ),
    'language' => array(
      'data' => t('Language'),
      'field' => 'language',
    ),
    'operations' => array(
      'data' => t('Operations'),
    ),
  );

  // Do not include the language column if locale is disabled.
  if (!module_exists('locale')) {
    unset($header['language']);
  }
  $rows = array();
  $destination = drupal_get_destination();
  $query = db_select('xmlsitemap')
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->fields('xmlsitemap');
  $query
    ->condition('type', 'custom');
  $query
    ->limit(25);
  $query
    ->orderByHeader($header);
  $result = $query
    ->execute();
  foreach ($result as $link) {
    $row = array();
    $row['loc'] = l($link->loc, $link->loc);
    $row['priority'] = number_format($link->priority, 1);
    $row['changefreq'] = $link->changefreq ? drupal_ucfirst(xmlsitemap_get_changefreq($link->changefreq)) : t('None');
    if (isset($header['language'])) {
      $row['language'] = module_invoke('locale', 'language_name', $link->language);
    }
    $operations = array();
    $operations['edit'] = xmlsitemap_get_operation_link('admin/config/search/xmlsitemap/custom/edit/' . $link->id, array(
      'title' => t('Edit'),
      'modal' => TRUE,
    ));
    $operations['delete'] = xmlsitemap_get_operation_link('admin/config/search/xmlsitemap/custom/delete/' . $link->id, array(
      'title' => t('Delete'),
      'modal' => TRUE,
    ));
    $row['operations'] = array(
      'data' => array(
        '#theme' => 'links',
        '#links' => $operations,
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      ),
    );
    $rows[] = $row;
  }

  // @todo Convert to tableselect
  $build['xmlsitemap_custom_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No custom links available.') . ' ' . l(t('Add custom link'), 'admin/config/search/xmlsitemap/custom/add', array(
      'query' => $destination,
    )),
  );
  $build['xmlsitemap_custom_pager'] = array(
    '#theme' => 'pager',
  );
  return $build;
}