You are here

function fasttoggle_user_fasttoggle_available_links in Fasttoggle 7

Implements hook_fasttoggle_available_links().

File

module/fasttoggle_user/fasttoggle_user.module, line 273

Code

function fasttoggle_user_fasttoggle_available_links($type = NULL, $obj = NULL) {
  if (!is_null($type) && $type != 'user') {
    return array();
  }
  $available_roles = fasttoggle_potential_toggleable_roles();
  $result = array(
    'user' => array(
      'id_field' => 'uid',
      'title_field' => 'name',
      'save_fn' => 'fasttoggle_user_save',
      'object_type' => 'user',
      'extra_settings' => array(
        'fasttoggle_allow_block_user1' => array(
          '#type' => 'checkbox',
          '#title' => t("Allow user 1's account to be blocked using Fasttoggle."),
          '#default_value' => variable_get('fasttoggle_allow_block_user1', 0),
        ),
        'fasttoggle_enhance_user_overview_page' => array(
          '#type' => 'checkbox',
          '#title' => t('Add blocked/unblocked toggle links to the user overview page.'),
          '#default_value' => variable_get('fasttoggle_enhance_user_overview_page', TRUE),
        ),
      ),
      'fields' => array(
        'status' => array(
          'instances' => array(
            'status' => array(
              'description' => t('Status <small>(unblocked/blocked)</small>'),
              'default' => TRUE,
              'access' => array(
                'fasttoggle_user_status_access',
              ),
              'labels' => array(
                FASTTOGGLE_LABEL_ACTION => array(
                  0 => t('unblock'),
                  1 => t('block'),
                ),
                FASTTOGGLE_LABEL_STATUS => array(
                  0 => t('blocked'),
                  1 => t('active'),
                ),
              ),
            ),
          ),
        ),
        'role' => array(
          '#title' => t('Roles that may be toggled'),
          'new_value_fn' => 'fasttoggle_get_user_role_array',
          'value_fn' => 'fasttoggle_get_user_role_option_value',
        ),
      ),
    ),
  );
  foreach ($available_roles as $rid => $role_name) {
    $safe_role = check_plain($role_name);
    $result['user']['fields']['role']['instances'][$rid] = array(
      'description' => ucfirst($safe_role),
      'default' => TRUE,
      'value_key' => $rid,
      'access' => array(
        'fasttoggle_user_role_access',
      ),
      'role' => $safe_role,
      'labels' => array(
        FASTTOGGLE_LABEL_ACTION => array(
          0 => t("Add role @role", array(
            '@role' => $safe_role,
          )),
          1 => t("Revoke @role role", array(
            '@role' => $safe_role,
          )),
        ),
        FASTTOGGLE_LABEL_STATUS => array(
          0 => t("Lacks role @role", array(
            '@role' => $safe_role,
          )),
          1 => t("Has @role role", array(
            '@role' => $safe_role,
          )),
        ),
      ),
    );
  }
  return $result;
}