You are here

function groupmenu_admin_menu_overview_form in Group Menu 7

Callback for admin/structure/groupmenu.

Just duplicates the standard menu list, but only displays those created through group_menu.

1 string reference to 'groupmenu_admin_menu_overview_form'
groupmenu_menu in ./groupmenu.module
Implements hook_menu().

File

./groupmenu.pages.inc, line 247
Page callbacks for groupmenu.

Code

function groupmenu_admin_menu_overview_form($form, $form_state) {
  $session = isset($_SESSION['groupmenu_filter']) ? $_SESSION['groupmenu_filter'] : array();

  // Get filter value from $_SESSION variable.
  foreach ($session as $filter) {
    list($type, $value) = $filter;
  }
  $form['filters'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => isset($type) ? FALSE : TRUE,
    '#title' => 'Filter',
    '#description' => t('Filter on the title of the Group menu.'),
  );
  $form['filters']['groupmenu_filter'] = array(
    '#type' => 'textfield',
    '#title' => t('Filter this out'),
    '#required' => FALSE,
    '#size' => 20,
    '#default_value' => isset($type) ? $value : '',
  );
  $form['filters']['groupmenu_actions'] = array(
    '#type' => 'actions',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  $form['filters']['groupmenu_actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Filter'),
  );
  if (count($session)) {
    $form['filters']['groupmenu_actions']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset'),
    );
  }
  $header = array(
    'title' => array(
      'data' => 'Title',
      'field' => 'title',
      'sort' => 'asc',
    ),
    'name' => array(
      'data' => 'Group Name',
      'field' => 'group_name',
    ),
    'list' => array(
      'data' => 'Operations',
      'colspan' => '4',
    ),
  );

  // Build Query (extend for paging and sorting).
  $query = db_select('menu_custom', 'mc')
    ->extend('PagerDefault')
    ->limit(20);

  // Pager Extender.
  $query
    ->join('group_menu', 'gm', 'mc.menu_name = gm.menu_name');
  $query
    ->join('groups', 'g', 'g.gid = gm.gid');
  $query
    ->fields('mc')
    ->fields('gm')
    ->orderBy('g.title')
    ->extend('TableSort')
    ->orderByHeader($header);
  $query
    ->addField('g', 'title', 'group_title');

  // Add conditional filter if enter by user.
  if (isset($type)) {
    $query
      ->condition('mg.title', '%' . $value . '%', 'LIKE');
  }
  $result = $query
    ->execute();

  // Build table.
  $options = array();
  foreach ($result as $menu) {
    $options[$menu->menu_name] = array(
      'title' => array(
        'data' => theme('menu_admin_overview', array(
          'title' => $menu->title,
          'name' => $menu->menu_name,
          'description' => $menu->description,
        )),
      ),
      'name' => array(
        'data' => $menu->group_title,
      ),
      'list' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => t('list links'),
          '#href' => 'admin/structure/menu/manage/' . $menu->menu_name,
        ),
      ),
      'edit' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => t('edit menu'),
          '#href' => 'admin/structure/menu/manage/' . $menu->menu_name . '/edit',
        ),
      ),
      'add' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => t('add link'),
          '#href' => 'admin/structure/menu/manage/' . $menu->menu_name . '/add',
        ),
      ),
      'view' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => t('view group'),
          '#href' => 'group/' . $menu->gid,
        ),
      ),
    );
  }
  $tableselect = array_sum(module_invoke_all('groupmenu_admin_menu_overview_form_tableselect'));
  if ($tableselect) {
    $form['groupmenu_menu_list'] = array(
      '#type' => 'tableselect',
      '#title' => t('Results'),
      '#header' => $header,
      '#options' => $options,
      '#empty' => 'Nothing to see',
      '#suffix' => theme('pager'),
    );
  }
  else {
    $output = theme('table', array(
      'header' => $header,
      'rows' => $options,
    )) . theme('pager');
    $form['groupmenu_menu_list'] = array(
      '#type' => 'markup',
      '#title' => t('Results'),
      '#markup' => $output,
    );
  }
  return $form;
}