You are here

function custom_breadcrumbs_page in Custom Breadcrumbs 7.2

Same name and namespace in other branches
  1. 5 custom_breadcrumbs.module \custom_breadcrumbs_page()
  2. 6.2 custom_breadcrumbs.admin.inc \custom_breadcrumbs_page()
  3. 6 custom_breadcrumbs.admin.inc \custom_breadcrumbs_page()
  4. 7 custom_breadcrumbs.admin.inc \custom_breadcrumbs_page()

Lists all current custom breadcrumbs and provides a link to the edit page.

1 string reference to 'custom_breadcrumbs_page'
custom_breadcrumbs_menu in ./custom_breadcrumbs.module
Implements hook_menu().

File

./custom_breadcrumbs.admin.inc, line 11
Admin page callback file for the custom_breadcrumbs module.

Code

function custom_breadcrumbs_page() {
  $custom_breadcrumbs_sort = variable_get('custom_breadcrumbs_sort', array(
    'direction' => array(
      'name' => 'asc',
      'breadcrumb_type' => 'asc',
      'language' => 'asc',
    ),
    'column' => 'name',
  ));
  $sort = $custom_breadcrumbs_sort['direction'];
  $multilingual = _custom_breadcrumbs_multilingual();
  $breadcrumbs = array();

  // Read session variable to load breadcrumbs of type and language selected by
  // user.
  if (empty($_SESSION['custom_breadcrumbs_overview_filter'])) {
    $breadcrumbs = _custom_breadcrumbs_load_all_breadcrumbs(TRUE);
  }
  else {

    // Determine a list of selected languages, and a list of modules to load
    // them from.
    $modules = array();
    $tables = array();
    $languages = array();
    foreach ($_SESSION['custom_breadcrumbs_overview_filter'] as $filter) {
      if ($filter[0] == 'type') {
        list($module, $table) = explode('-', $filter[1]);
        $modules[] = $module;
        $tables[] = $table;
      }
      elseif ($filter[0] == 'language') {
        $languages[] = $filter[1];
      }
    }
    if (empty($modules)) {
      $modules = module_implements('cb_breadcrumb_info');
    }
    foreach ($modules as $key => $module) {
      $more = custom_breadcrumbs_load_breadcrumbs($module, $tables[$key], NULL, $languages);
      if (!empty($more)) {
        $breadcrumbs = array_merge($breadcrumbs, $more);
      }
    }
  }

  // Sort the breadcrumbs according to $sort and $order.
  $columns = array(
    'name' => 'Name',
    'breadcrumb_type' => 'Breadcrumb Type',
  );
  if ($multilingual) {
    $columns['language'] = 'Language';
  }
  $order = isset($_GET['order']) && in_array($_GET['order'], array_keys($columns)) ? $_GET['order'] : 'name';
  $sort[$order] = isset($_GET['sort']) && $_GET['sort'] == 'desc' ? 'desc' : 'asc';
  variable_set('custom_breadcrumbs_sort', array(
    'direction' => $sort,
    'column' => $order,
  ));
  usort($breadcrumbs, '_custom_breadcrumbs_sort_cmp');

  // Make the breadcrumb list table sortable by name, type and language.
  $path = 'admin/structure/custom_breadcrumbs';
  $sort[$order] = $sort[$order] == 'asc' ? 'desc' : 'asc';

  // Add an arrow indicating sort direction.
  $image = array(
    $order => theme('tablesort_indicator', array(
      'style' => array(
        'style' => $sort[$order],
      ),
    )),
  );
  $headers = array();
  foreach ($columns as $key => $title) {
    $options = array(
      'attributes' => array(
        'title' => t('sort by @s', array(
          '@s' => $title,
        )),
      ),
    );
    $options['query'] = array(
      'order' => $key,
      'sort' => $sort[$key],
    );
    if (isset($image[$key])) {
      $options['html'] = TRUE;
      $title .= $image[$key];
    }
    $headers[] = array(
      'data' => l($title, $path, $options),
    );
  }
  $headers[] = t('Operations');
  $rows = array();
  foreach ($breadcrumbs as $breadcrumb) {
    $row = array();
    $name = $breadcrumb->name;
    $type = $breadcrumb->breadcrumb_type;
    $row['name'] = array(
      'data' => $name . (!empty($breadcrumb->visibility_php) ? ' ' . t('with PHP snippet') : ''),
    );
    $row['breadcrumb_type'] = array(
      'data' => $type,
    );
    if ($multilingual) {
      $row['language'] = array(
        'data' => module_invoke('locale', 'language_name', $breadcrumb->language),
      );
    }
    $row['edit'] = l(t('edit'), $path . '/' . $breadcrumb->breadcrumb_type . '/edit/' . $breadcrumb->bid);
    $row[$order]['class'] = 'active';
    $rows[] = $row;
  }
  if (count($rows) == 0) {
    $rows[] = array(
      array(
        'data' => t('No custom breadcrumbs have been defined.'),
        'colspan' => 2 + (int) $multilingual,
      ),
    );
  }

  // Prepare help text for this page. Not sure why this doesn't work in
  // hook_help().
  $output = '<p>' . t("To create a custom breadcrumb, choose one of the breadcrumb types listed above. The following table lists all of the custom breadcrumbs that have been defined. The list can be filtered by breadcrumb type or language, or sorted by clicking on one of the column headings.") . '</p>';
  $output .= '<p>' . t('You can configure Custom Breadcrumb settings at <a href="@link">admin/config/user-interface/custom-breadcrumbs</a>.', array(
    '@link' => url('admin/config/user-interface/custom-breadcrumbs'),
  )) . '</p>';
  $build = array();
  $build['help_text'] = array(
    '#markup' => $output,
  );
  $build['filter_form'] = drupal_get_form('custom_breadcrumbs_filter_form');
  $build['breadcrumb_table'] = array(
    '#markup' => theme('table', array(
      'header' => $headers,
      'rows' => $rows,
    )),
  );
  return $build;
}