You are here

function menu_badges_tabs_admin_form in Menu Badges 7

Admin form for adding badges to tabs.

_state

Parameters

$form:

1 string reference to 'menu_badges_tabs_admin_form'
menu_badges_menu in ./menu_badges.module
Implements hook_menu().

File

./menu_badges.admin.inc, line 12
Menu Badges admin forms.

Code

function menu_badges_tabs_admin_form($form, $form_state) {
  $badges = menu_badges_get_badges();
  $form['#tree'] = TRUE;
  $form['#attached']['css'] = array(
    drupal_get_path('module', 'menu_badges') . '/menu_badges.css',
  );
  $form['search'] = array(
    '#type' => 'fieldset',
    '#title' => t('Search'),
  );
  $form['search']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#size' => 30,
  );
  $form['search']['path'] = array(
    '#type' => 'textfield',
    '#title' => t('Menu Path'),
    '#size' => 30,
  );
  $form['search']['type'] = array(
    '#type' => 'select',
    '#title' => t('Menu Type'),
    '#options' => array(
      '' => '',
      MENU_DEFAULT_LOCAL_TASK => t('Tab (MENU_DEFAULT_LOCAL_TASK)'),
      MENU_LOCAL_TASK => t('Tab (MENU_LOCAL_TASK)'),
      MENU_LOCAL_ACTION => t('Action Link (MENU_LOCAL_ACTION)'),
    ),
  );
  $form['search']['search'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );
  $query = db_select('menu_router', 'mr')
    ->fields('mr', array(
    'path',
    'type',
    'title',
  ));
  if (!empty($form_state['input']['search']['title'])) {
    $query
      ->condition('title', '%' . $form_state['input']['search']['title'] . '%', 'LIKE');
  }
  if (!empty($form_state['input']['search']['path'])) {
    $query
      ->condition('path', '%' . $form_state['input']['search']['path'] . '%', 'LIKE');
  }
  if (!empty($form_state['input']['search']['type'])) {
    $query
      ->condition('type', $form_state['input']['search']['type'], '=');
  }
  else {
    $query
      ->condition('type', array(
      MENU_DEFAULT_LOCAL_TASK,
      MENU_LOCAL_TASK,
      MENU_LOCAL_ACTION,
    ), 'IN');
  }
  $results = $query
    ->extend('PagerDefault')
    ->limit(25)
    ->execute();
  $menu_badge_options = array(
    '' => t('None'),
  ) + menu_badges_get_badge_options();
  $tab_badges = variable_get('menu_badges_tab_callbacks', array());
  $form['results'] = array();
  foreach ($results as $record) {
    $form['results'][$record->path] = array();
    $form['results'][$record->path]['path'] = array(
      '#type' => 'value',
      '#value' => $record->path,
    );
    $form['results'][$record->path]['title'] = array(
      '#type' => 'value',
      '#value' => $record->title,
    );
    $form['results'][$record->path]['type'] = array(
      '#type' => 'value',
      '#value' => $record->type,
    );
    $form['results'][$record->path]['menu_badges_callback'] = array(
      '#type' => 'select',
      '#options' => $menu_badge_options,
      '#default_value' => !empty($tab_badges[$record->path]) ? $tab_badges[$record->path]['key'] : '',
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}