You are here

function login_destination_overview_form in Login Destination 7

Form for editing an entire login destination at once.

Shows list of all login destination.

1 string reference to 'login_destination_overview_form'
login_destination_menu in ./login_destination.module
Implements hook_menu().

File

./login_destination.admin.inc, line 13
Admin page callback file for the Login Destination module.

Code

function login_destination_overview_form($form, &$form_state) {

  // Get all login destination rules from the database.
  $result = db_select('login_destination', 'l')
    ->fields('l', array(
    'id',
    'triggers',
    'roles',
    'pages_type',
    'pages',
    'destination',
    'weight',
    'enabled',
  ))
    ->orderBy('weight')
    ->execute()
    ->fetchAll();
  $form['#tree'] = TRUE;

  // Loop through the categories and add them to the table.
  foreach ($result as $data) {
    $triggers = array_map('check_plain', unserialize($data->triggers));
    if (empty($triggers)) {
      $triggers = array();
    }
    $roles = array_map('check_plain', unserialize($data->roles));
    if (empty($roles)) {
      $roles = array();
    }
    $form[$data->id]['destination']['#markup'] = theme('login_destination_destination', array(
      'destination' => $data->destination,
    ));
    $form[$data->id]['triggers']['#markup'] = theme('login_destination_triggers', array(
      'items' => $triggers,
    ));
    $form[$data->id]['pages']['#markup'] = theme('login_destination_pages', array(
      'pages' => $data->pages,
      'pages_type' => $data->pages_type,
    ));
    $form[$data->id]['roles']['#markup'] = theme('login_destination_roles', array(
      'items' => $roles,
    ));
    $form[$data->id]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#delta' => 50,
      '#default_value' => $data->weight,
      '#title_display' => 'invisible',
    );
    $form[$data->id]['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enabled'),
      '#default_value' => $data->enabled,
      '#title_display' => 'invisible',
    );

    // Build a list of operations.
    $operations = array();
    $operations['edit'] = array(
      '#type' => 'link',
      '#title' => t('edit'),
      '#href' => 'admin/config/people/login-destination/edit/' . $data->id,
    );
    $operations['delete'] = array(
      '#type' => 'link',
      '#title' => t('delete'),
      '#href' => 'admin/config/people/login-destination/delete/' . $data->id,
    );
    $form[$data->id]['operations'] = $operations;
  }
  if (element_children($form)) {
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save configuration'),
    );
  }
  else {
    $form['#empty_text'] = t('There is no Login Destination Rule.');
  }
  return $form;
}