You are here

function _search_by_page_paths_list_page in Search by Page 8

Page callback for path listings page.

Builds a page that lists existing paths to index, with links to edit, delete, and add new.

1 string reference to '_search_by_page_paths_list_page'
search_by_page_paths_menu in search_by_page_paths/search_by_page_paths.module
Implements hook_menu().

File

search_by_page_paths/search_by_page_paths.module, line 272
Module file for Search by Page Paths, a sub-module for Search by Page.

Code

function _search_by_page_paths_list_page($environment) {
  $output = '';
  $environment = intval($environment);

  // Overview
  $output .= '<p>' . t('This page allows you to define pages on your site to be indexed by the Search by Page module in this environment.') . '</p>' . "\n";

  // Link to add a new path
  $basepath = 'admin/config/search/search_by_page/edit/' . $environment . '/paths/';
  $output .= '<p>' . l(t('Add new path'), $basepath . 'add') . '</p>' . "\n";

  // List existing paths in a table, with edit/delete links
  // and use a pager
  $query = \Drupal::database()
    ->select('sbpp_path', 'p')
    ->extend('PagerDefault');
  $query
    ->addField('p', 'pid');
  $query
    ->addField('p', 'page_path');
  $query
    ->addField('p', 'title');
  $query
    ->condition('environment', $environment)
    ->limit(50)
    ->orderBy('page_path');
  $result = $query
    ->execute()
    ->fetchAll();
  $headers = array(
    t('Path'),
    t('Title'),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $rows = array();
  foreach ($result as $data) {
    $rows[] = array(
      Html::escape($data->page_path),
      Html::escape($data->title),
      l(t('edit'), $basepath . 'edit/' . $data->pid),
      l(t('delete'), $basepath . 'delete/' . $data->pid),
    );
  }
  $output .= theme('table', array(
    'header' => $headers,
    'rows' => $rows,
  ));
  $output .= theme('pager', array(
    'tags' => NULL,
  ));
  return $output;
}