You are here

function drop_down_login_settings in Drop Down Login 7

Callback for drop down login setting form.

1 string reference to 'drop_down_login_settings'
drop_down_login_menu in ./drop_down_login.module
Implements hook_menu().

File

./drop_down_login.admin.inc, line 11
Drop down login administration and module settings UI.

Code

function drop_down_login_settings($form, &$form_state) {
  $profile_pic_default_value = variable_get('drop_down_login_profile_pic');
  $drop_down_login_bootstrap = variable_get('drop_down_login_bootstrap_theme');
  $form['#attached']['css'] = array(
    drupal_get_path('module', 'drop_down_login') . '/theme/drop_down_login.css',
  );
  $form['drop_down_login_setting']['login_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Text for Login Button'),
    '#default_value' => variable_get('login_text', 'Login'),
    '#description' => t('Change the text for Login'),
  );
  $form['drop_down_login_setting']['logout_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Text for Logout Button'),
    '#default_value' => variable_get('logout_text', 'Logout'),
    '#description' => t('Change the text for Logout.'),
  );
  $form['drop_down_login_setting']['drop_down_login_want_myaccount'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable My Account drop-down after login.'),
    '#default_value' => variable_get('drop_down_login_want_myaccount'),
    '#description' => t('If you want a drop-down menu to appear with "View Profile"
            and "Logout" (as well as optional links you specify below between these two
            options) instead of just the logout button, check this box.'),
  );
  $form['drop_down_login_setting']['drop_down_login_profile_pic'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use profile image as icon on My account menu'),
    '#default_value' => isset($profile_pic_default_value) ? $profile_pic_default_value : '',
    '#description' => t('Allow user to set profile image as icon on My account menu.'),
  );
  $form['drop_down_login_setting']['drop_down_login_bootstrap_theme'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use drop down login module with Bootstrap theme.'),
    '#default_value' => isset($drop_down_login_bootstrap) ? $drop_down_login_bootstrap : '',
    '#description' => t('Allow user to set Bootstrap compatible template. This option will only work if current theme is a Bootstrap theme or a sub theme of bootstrap.'),
  );
  $form['drop_down_login_setting']['my_account_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Text for My Account'),
    '#default_value' => variable_get('my_account_text', 'My Account'),
    '#description' => t('Change the text for My Account'),
    '#states' => array(
      'visible' => array(
        ':input[name=drop_down_login_want_myaccount]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['drop_down_login_myaccount_links'] = array(
    '#type' => 'fieldset',
    '#weight' => 80,
    '#tree' => TRUE,
    '#title' => t('Additional Links'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    // Set up the wrapper so that AJAX will be able to replace the fieldset.
    '#prefix' => '<div id="js-ajax-elements-wrapper">',
    '#suffix' => '</div>',
    '#description' => t('If you chose to enable the "My Account" drop-down after login,
            you can include additional links by completing the fields below, one set
            for each link.'),
  );
  $drop_down_login_myaccount_links = variable_get('drop_down_login_myaccount_links', array());
  usort($drop_down_login_myaccount_links, function ($a, $b) {
    return $a['weight'] - $b['weight'];
  });
  $numb_links = count($drop_down_login_myaccount_links);
  $links_deltas = $numb_links > 0 ? range(0, $numb_links - 1) : array();
  $form_state['field_deltas'] = isset($form_state['field_deltas']) ? $form_state['field_deltas'] : $links_deltas;
  $field_count = $form_state['field_deltas'];
  foreach ($field_count as $delta) {
    $form['drop_down_login_myaccount_links'][$delta] = array(
      '#type' => 'container',
      '#attributes' => array(
        'class' => array(
          'container-inline',
        ),
      ),
      '#tree' => TRUE,
    );
    $form['drop_down_login_myaccount_links'][$delta]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#default_value' => !empty($drop_down_login_myaccount_links[$delta]) ? $drop_down_login_myaccount_links[$delta]['weight'] : '',
      '#title-display' => 'invisible',
      // A class is required by drag and drop.
      '#attributes' => array(
        'class' => array(
          'drop-down-login-item-weight',
        ),
      ),
    );
    $form['drop_down_login_myaccount_links'][$delta]['menu']['menu_name'] = array(
      '#type' => 'textfield',
      '#title' => t('Menu Name'),
      '#size' => 60,
      '#required' => TRUE,
      '#default_value' => !empty($drop_down_login_myaccount_links[$delta]) ? $drop_down_login_myaccount_links[$delta]['menu']['menu_name'] : '',
      '#description' => t('The text to be used for this link in the My Account drop down.'),
    );
    $form['drop_down_login_myaccount_links'][$delta]['menu']['menu_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Menu URL'),
      '#size' => 60,
      '#required' => TRUE,
      '#max_length' => 512,
      '#element_validate' => array(
        'drop_down_login_menu_edit_item_validate',
      ),
      '#default_value' => !empty($drop_down_login_myaccount_links[$delta]) ? $drop_down_login_myaccount_links[$delta]['menu']['menu_url'] : '',
      '#description' => t('The path for this menu link. This can be an internal Drupal path such as node/add or an external URL such as http://drupal.org. Enter :front to link to the front page.', array(
        ':front' => "<front>",
      )),
    );
    $form['drop_down_login_myaccount_links'][$delta]['menu']['remove_name'] = array(
      '#type' => 'submit',
      '#value' => t('- Remove'),
      '#submit' => array(
        'drop_down_login_ajax_add_more_remove',
      ),
      '#limit_validation_errors' => array(),
      // See the examples in ajax_example.module for more details on the
      // properties of #ajax.
      '#ajax' => array(
        'callback' => 'drop_down_login_ajax_add_more_remove_callback',
        'wrapper' => 'js-ajax-elements-wrapper',
      ),
      '#weight' => -50,
      '#attributes' => array(
        'class' => array(
          'button-small',
        ),
      ),
      '#name' => 'remove_name_' . $delta,
    );
  }
  $form['drop_down_login_myaccount_links']['add_name'] = array(
    '#type' => 'submit',
    '#value' => t('Add a link'),
    '#submit' => array(
      'drop_down_login_ajax_add_more_add_one',
    ),
    '#limit_validation_errors' => array(),
    // See the examples in ajax_example.module for more details on the
    // properties of #ajax.
    '#ajax' => array(
      'callback' => 'drop_down_login_ajax_add_more_add_one_callback',
      'wrapper' => 'js-ajax-elements-wrapper',
    ),
    '#weight' => 100,
  );
  $form['drop_down_login_myaccount_links']['#theme'] = 'drop_down_login_dragandrop';
  return system_settings_form($form);
}