diff --git a/login_destination.admin.inc b/login_destination.admin.inc index a2743ac..802b408 100755 --- a/login_destination.admin.inc +++ b/login_destination.admin.inc @@ -6,335 +6,6 @@ */ /** - * List destination rules. - */ -function login_destination_overview() { - $header = array( - t('Destination'), - t('Triggers'), - t('Pages'), - t('Roles'), - array('data' => t('Operations'), 'colspan' => 2), - ); - $rows = array(); - - // Get all login destination rules from the database. - $result = db_select('login_destination', 'l') - ->fields('l', array('id', 'triggers', 'roles', 'pages_type', 'pages', 'destination')) - ->orderBy('weight') - ->execute() - ->fetchAll(); - - // 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(); - - $rows[] = array( - theme('login_destination_destination', array('destination' => $data->destination)), - theme('login_destination_triggers', array('items' => $triggers)), - theme('login_destination_pages', array('pages' => $data->pages, 'pages_type' => $data->pages_type)), - theme('login_destination_roles', array('items' => $roles)), - l(t('Edit'), 'admin/config/people/login-destination/edit/' . $data->id), - l(t('Delete'), 'admin/config/people/login-destination/delete/' . $data->id), - ); - } - - if (!$rows) { - $rows[] = array(array( - 'data' => t('No rules available.'), - 'colspan' => 6, - )); - } - - $build['login-destination_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - ); - return $build; -} - -function theme_login_destination_destination($variables) { - $output = nl2br(check_plain($variables['destination'])); - - if (empty($output)) { - $output = '' . t('Empty') . ''; - } - - return $output; -} - -function theme_login_destination_triggers($variables) { - $items = array_map('check_plain', $variables['items']); - - if (empty($items)) { - return '' . t('All triggers') . ''; - } - - $output = ''; - foreach ($items as &$item) { - switch ($item) { - case 'login': - $item = 'Login'; - break; - case 'logout': - $item = 'Logout'; - break; - } - $output .= $item . "
"; - } - - return $output; -} - -function theme_login_destination_pages($variables) { - $type = $variables['pages_type']; - - if ($type == LOGIN_DESTINATION_REDIRECT_PHP) { - return nl2br(check_plain($variables['pages'])); - } - - $pages = trim($variables['pages']); - - if (empty($pages)) { - if ($type == LOGIN_DESTINATION_REDIRECT_NOTLISTED) { - return '' . t('All pages') . ''; - } - else { - return '' . t('No pages') . ''; - } - } - - $pages = explode("\n", preg_replace('/\r/', '', check_plain($variables['pages']))); - - $output = ''; - foreach ($pages as &$page) { - if ($type == LOGIN_DESTINATION_REDIRECT_NOTLISTED) { - $output .= "~ "; - } - $output .= $page . "
"; - } - - return $output; -} - -function theme_login_destination_roles($variables) { - $items = array_values(array_intersect_key(_login_destination_role_options(), $variables['items'])); - - if (empty($items)) { - return '' . t('All roles') . ''; - } - - return theme('item_list', array('items' => $items)); -} - -/** - * Category edit page. - */ -function login_destination_edit_form($form, &$form_state, array $rule = array()) { - // default values - $rule += array( - 'triggers' => array(), - 'roles' => array(), - 'pages_type' => LOGIN_DESTINATION_REDIRECT_NOTLISTED, - 'pages' => '', - 'destination_type' => LOGIN_DESTINATION_STATIC, - 'destination' => '', - 'id' => NULL, - 'weight' => 0, - ); - - $access = user_access('use PHP for settings'); - - $type = $rule['destination_type']; - - if ($type == LOGIN_DESTINATION_SNIPPET && !$access) { - $form['destination_type'] = array( - '#type' => 'value', - '#value' => LOGIN_DESTINATION_SNIPPET, - ); - $form['destination'] = array( - '#type' => 'value', - '#value' => $rule['destination'], - ); - } - else { - $options = array( - LOGIN_DESTINATION_STATIC => t('Internal page or external URL'), - ); - $description = t("Specify page by using its path. Example path is %blog for the blog page. %front is the front page. %current is the current page. Precede with http:// for an external URL. Leave empty to redirect to a default page.", array('%blog' => 'blog', '%front' => '', '%current' => '')); - - if (module_exists('php') && $access) { - $options += array(LOGIN_DESTINATION_SNIPPET => t('Page returned by this PHP code (experts only)')); - $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. It should return either a string value or an array of params that the %function function will understand, e.g. %example. For more information, see the online API entry for url function. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '', '%function' => 'url($path = \'\', array $options = array())', '%example' => ' \'overlay=admin/config\', ), ); ?>', '@url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url/7')); - } - - $form['destination_type'] = array( - '#type' => 'radios', - '#title' => 'Redirect to page', - '#default_value' => $type, - '#options' => $options, - ); - $form['destination'] = array( - '#type' => 'textarea', - '#default_value' => $rule['destination'], - '#description' => $description, - ); - } - - $triggers = array_map('check_plain', $rule['triggers']); - if (empty($triggers)) { - $triggers = array(); - } - - $form['triggers'] = array( - '#type' => 'checkboxes', - '#title' => t('Redirect upon triggers'), - '#options' => array('login' => 'Login, registration, one-time login link', 'logout' => 'Logout'), - '#default_value' => $triggers, - '#description' => 'Redirect only upon selected trigger(s). If you select no triggers, all of them will be used.', - ); - - $type = $rule['pages_type']; - - if ($type == LOGIN_DESTINATION_REDIRECT_PHP && !$access) { - $form['pages_type'] = array( - '#type' => 'value', - '#value' => LOGIN_DESTINATION_REDIRECT_PHP, - ); - $form['pages'] = array( - '#type' => 'value', - '#value' => $rule['destination'], - ); - } - else { - $options = array( - LOGIN_DESTINATION_REDIRECT_NOTLISTED => t('All pages except those listed'), - LOGIN_DESTINATION_REDIRECT_LISTED => t('Only the listed pages'), - ); - $description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. %login is the login form. %register is the registration form. %reset is the one-time login (e-mail validation).", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '', '%login' => 'user', '%register' => 'user/register', '%reset' => 'user/*/edit')); - - if (module_exists('php') && $access) { - $options += array(LOGIN_DESTINATION_REDIRECT_PHP => t('Pages on which this PHP code returns TRUE (experts only)')); - $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '')); - } - - $form['pages_type'] = array( - '#type' => 'radios', - '#title' => t('Redirect from specific pages'), - '#default_value' => $type, - '#options' => $options, - ); - $form['pages'] = array( - '#type' => 'textarea', - '#default_value' => $rule['pages'], - '#description' => $description, - ); - } - - $default_role_options = array_map('check_plain', $rule['roles']); - if (empty($default_role_options)) { - $default_role_options = array(); - } - - $form['roles'] = array( - '#type' => 'checkboxes', - '#title' => t('Redirect users with roles'), - '#options' => _login_destination_role_options(), - '#default_value' => $default_role_options, - '#description' => 'Redirect only the selected role(s). If you select no roles, all users will be redirected.', - ); - - $form['weight'] = array( - '#type' => 'weight', - '#title' => t('Weight'), - '#default_value' => $rule['weight'], - '#description' => t('When evaluating login destination rules, those with lighter (smaller) weights get evaluated before rules with heavier (larger) weights.'), - ); - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Save'), - ); - - if ($rule['id']) { - $form['id'] = array( - '#type' => 'hidden', - '#value' => $rule['id'], - ); - } - - return $form; -} - -/** - * Validate the contact category edit page form submission. - */ -function login_destination_edit_form_validate($form, &$form_state) { -} - -/** - * Process the contact category edit page form submission. - */ -function login_destination_edit_form_submit($form, &$form_state) { - $form_state['values']['triggers'] = serialize(array_filter($form_state['values']['triggers'])); - $form_state['values']['roles'] = serialize(array_filter($form_state['values']['roles'])); - - if (empty($form_state['values']['id'])) { - drupal_write_record('login_destination', $form_state['values']); - } - else { - drupal_write_record('login_destination', $form_state['values'], array('id')); - } - - drupal_set_message(t('Login destination to %destination has been saved.', array('%destination' => $form_state['values']['destination']))); - - $form_state['redirect'] = 'admin/config/people/login-destination'; -} - -/** - * Form builder for deleting a login destination. - */ -function login_destination_delete_form($form, &$form_state, array $rule) { - $form['login_destination'] = array( - '#type' => 'value', - '#value' => $rule, - ); - - return confirm_form( - $form, - t('Are you sure you want to delete the login destination %destination ?', array('%destination' => $rule['destination'])), - 'admin/config/people/login-destination', - t('This action cannot be undone.'), - t('Delete'), - t('Cancel') - ); -} - -/** - * Submit handler for the confirm delete login destination form. - */ -function login_destination_delete_form_submit($form, &$form_state) { - $rule = $form['login_destination']['#value']; - - db_delete('login_destination') - ->condition('id', $rule['id']) - ->execute(); - - drupal_set_message(t('The login destination %destination has been deleted.', array('%destination' => $rule['destination']))); - - $form_state['redirect'] = 'admin/config/people/login-destination'; -} - -/** * Settings page. */ function login_destination_settings() { diff --git a/login_destination.info b/login_destination.info index 7fd1b30..318fba6 100644 --- a/login_destination.info +++ b/login_destination.info @@ -4,4 +4,5 @@ description = Customize the destination that the user is redirected to after log core = 7.x files[] = login_destination.module files[] = login_destination.admin.inc +dependencies[] = ctools configure = admin/config/people/login-destination \ No newline at end of file diff --git a/login_destination.install b/login_destination.install index 0c306e0..76ab3dd 100644 --- a/login_destination.install +++ b/login_destination.install @@ -11,6 +11,20 @@ function login_destination_schema() { $schema['login_destination'] = array( 'description' => 'Login Destination rules.', + 'export' => array( + 'key' => 'name', + 'key name' => 'Name', + 'admin_title' => 'label', + 'primary key' => 'id', + 'identifier' => 'login_destination', // Exports will be defined as $login_destination + 'default hook' => 'default_login_destination', // Function hook name. + 'api' => array( + 'owner' => 'login_destination', + 'api' => 'default_login_destination', // Base name for api include files. + 'minimum_version' => 1, + 'current_version' => 1, + ), + ), 'fields' => array( 'id' => array( 'type' => 'serial', @@ -18,15 +32,29 @@ function login_destination_schema() { 'not null' => TRUE, 'description' => 'Primary Key: Unique ID.', ), + 'name' => array( + 'type' => 'varchar', + 'length' => '255', + 'description' => 'Unique ID for presets. Used to identify them programmatically.', + ), + 'label' => array( + 'type' => 'varchar', + 'length' => '255', + 'description' => 'Administrative label for this object.', + ), 'triggers' => array( 'type' => 'text', 'not null' => TRUE, 'description' => 'Triggers on which to perform redirect', + 'serialize' => TRUE, + 'object default' => array(), ), 'roles' => array( 'type' => 'text', 'not null' => TRUE, 'description' => 'Roles to perform redirect for', + 'serialize' => TRUE, + 'object default' => array(), ), 'pages_type' => array( 'type' => 'int', @@ -39,6 +67,7 @@ function login_destination_schema() { 'type' => 'text', 'not null' => TRUE, 'description' => 'Pages from which to redirect', + 'object default' => '', ), 'destination_type' => array( 'type' => 'int', @@ -51,6 +80,7 @@ function login_destination_schema() { 'type' => 'text', 'not null' => TRUE, 'description' => 'Redirect destination', + 'object default' => '', ), 'weight' => array( 'type' => 'int', @@ -63,6 +93,9 @@ function login_destination_schema() { 'indexes' => array( 'list' => array('weight'), ), + 'unique keys' => array( + 'name' => array('name'), + ), ); return $schema; @@ -125,8 +158,8 @@ function login_destination_update_7000() { $form_state['values']['destination'] = $snippet; } - $form_state['values']['triggers'] = serialize(array('login')); - $form_state['values']['roles'] = serialize(array()); + $form_state['values']['triggers'] = array('login'); + $form_state['values']['roles'] = array(); drupal_write_record('login_destination', $form_state['values']); @@ -138,3 +171,28 @@ function login_destination_update_7000() { variable_del('ld_url_type'); variable_del('ld_url_destination'); } + +/** + * Add the name column to the database. + */ +function login_destination_update_7001() { + // Add the name field. + db_add_field('login_destination', 'name', array( + 'type' => 'varchar', + 'length' => '255', + 'description' => 'Unique ID for presets. Used to identify them programmatically.', + )); + // Add the label field. + db_add_field('login_destination', 'label', array( + 'type' => 'varchar', + 'length' => '255', + 'description' => 'Administrative label for this object.', + )); + // Generate unique names. + db_update('login_destination') + ->expression('name', 'CONCAT(:name, id)', array(':name' => 'login_destination_')) + ->expression('label', 'CONCAT(:label, id)', array(':label' => 'Login Destination ')) + ->execute(); + // Add the unique key. + db_add_unique_key('login_destination', 'name', array('name')); +} \ No newline at end of file diff --git a/login_destination.module b/login_destination.module index 2ad4262..1b743e2 100644 --- a/login_destination.module +++ b/login_destination.module @@ -33,42 +33,6 @@ function login_destination_help($path, $arg) { * Implements hook_menu(). */ function login_destination_menu() { - $items['admin/config/people/login-destination'] = array( - 'title' => 'Login destinations', - 'description' => 'Customize the destination that the user is redirected to after login.', - 'page callback' => 'login_destination_overview', - 'access arguments' => array('administer users'), - 'file' => 'login_destination.admin.inc', - 'weight' => 10, - ); - $items['admin/config/people/login-destination/add'] = array( - 'title' => 'Add login destination rule', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('login_destination_edit_form'), - 'access arguments' => array('administer users'), - 'type' => MENU_LOCAL_ACTION, - 'weight' => 1, - 'file' => 'login_destination.admin.inc', - ); - $items['admin/config/people/login-destination/edit/%login_destination'] = array( - 'title' => 'Edit login destination rule', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('login_destination_edit_form', 5), - 'access arguments' => array('administer users'), - 'file' => 'login_destination.admin.inc', - ); - $items['admin/config/people/login-destination/delete/%login_destination'] = array( - 'title' => 'Delete login destination rule', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('login_destination_delete_form', 5), - 'access arguments' => array('administer users'), - 'file' => 'login_destination.admin.inc', - ); - $items['admin/config/people/login-destination/list'] = array( - 'title' => 'List', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, - ); $items['admin/config/people/login-destination/settings'] = array( 'title' => 'Settings', 'description' => 'Change Login Destination settings.', @@ -86,48 +50,12 @@ function login_destination_menu() { /** * Load a login destination. */ -function login_destination_load($id) { - $result = db_select('login_destination', 'l') - ->fields('l') - ->condition('id', $id) - ->execute() - ->fetchAssoc(); - - $result['triggers'] = unserialize($result['triggers']); - if (empty($result['triggers'])) { - $result['triggers'] = array(); +function login_destination_load($name = NULL) { + ctools_include('export'); + if ($name) { + return ctools_export_crud_load('login_destination', $name); } - - $result['roles'] = unserialize($result['roles']); - if (empty($result['roles'])) { - $result['roles'] = array(); - } - - return $result; -} - -/** - * Implements hook_theme - */ -function login_destination_theme() { - return array( - 'login_destination_destination' => array( - 'variables' => array('destination' => NULL), - 'file' => 'login_destination.admin.inc', - ), - 'login_destination_pages' => array( - 'variables' => array('pages' => NULL, 'pages_type' => 0), - 'file' => 'login_destination.admin.inc', - ), - 'login_destination_triggers' => array( - 'variables' => array('items' => NULL), - 'file' => 'login_destination.admin.inc', - ), - 'login_destination_roles' => array( - 'variables' => array('items' => NULL), - 'file' => 'login_destination.admin.inc', - ), - ); + return ctools_export_crud_load_all('login_destination'); } /** @@ -187,14 +115,14 @@ function login_destination_validate($form, &$form_state) { } break; } - + // Fix the current page in case of 403 page. if ($form['#form_id'] == 'user_login') { if(drupal_get_http_header('Status') == '403 Forbidden') { $_GET['current'] = $_GET['destination']; } } - + } /** @@ -333,16 +261,11 @@ function login_destination_perform_redirect($trigger = '', $current = NULL) { * This function is intended to be used by external modules. */ function login_destination_get_destination($trigger = '', $current = NULL) { - // Get all the login destination rules from the database. - $result = db_select('login_destination', 'l') - //->addTag('translatable') - ->fields('l', array('triggers', 'roles', 'pages_type', 'pages', 'destination_type', 'destination')) - ->orderBy('weight') - ->execute() - ->fetchAll(); + // Get all the login destination rules. + $result = login_destination_load(); if ($current == NULL) { - $current = $_GET['q']; + $current = current_path(); } // examine path matches @@ -388,7 +311,7 @@ function _login_destination_get_current($trigger = '') { } if ($trigger == 'login') { - return $_GET['q']; + return current_path(); } // front by default @@ -406,16 +329,9 @@ function _login_destination_match_rule($rule, $trigger = '', $current = NULL) { $type = $rule->pages_type; $pages = $rule->pages; - $triggers = unserialize($rule->triggers); - if (empty($triggers)) - $triggers = array(); - - $roles = unserialize($rule->roles); - if (empty($roles)) - $roles = array(); - + $triggers = $rule->triggers; // remove non-existent roles - $roles = array_intersect_key(_login_destination_role_options(), $roles); + $roles = array_intersect_key(_login_destination_role_options(), $rule->roles); // examine trigger match if (!(empty($triggers) || array_key_exists($trigger, $triggers))) { @@ -502,3 +418,24 @@ function _login_destination_evaluate_rule($rule, $trigger = '') { return FALSE; } } + +/** + * Implementation of hook_ctools_plugin_api(). + * + * Tell CTools that we support the default_login_destination API. + */ +function login_destination_ctools_plugin_api($owner, $api) { + if ($owner == 'login_destination' && $api == 'default_login_destination') { + return array('version' => 1); + } +} + +/** + * Implementation of hook_ctools_plugin_directory(). + */ +function login_destination_ctools_plugin_directory($module, $type) { + // Load the export_ui plugin. + if ($type =='export_ui') { + return 'plugins/export_ui'; + } +} diff --git a/plugins/export_ui/login_destination_ctools_export_ui.inc b/plugins/export_ui/login_destination_ctools_export_ui.inc new file mode 100644 index 0000000..380df68 --- /dev/null +++ b/plugins/export_ui/login_destination_ctools_export_ui.inc @@ -0,0 +1,146 @@ + 'login_destination', // As defined in hook_schema(). + 'access' => 'administer users', // Define a permission users must have to access these pages. + + // Define the menu item. + 'menu' => array( + 'menu prefix' => 'admin/config/people', + 'menu item' => 'login-destination', + 'menu title' => 'Login destinations', + 'menu description' => 'Customize the destination that the user is redirected to after login.', + ), + + // Define user interface texts. + 'title singular' => t('Login destination'), + 'title plural' => t('Login destinations'), + 'title singular proper' => t('Login destination'), + 'title plural proper' => t('Login destinations'), + + // Define the names of the functions that provide the add/edit forms. + 'form' => array( + 'settings' => 'login_destination_edit_form', + // 'submit' and 'validate' are also valid callbacks. + ), +); + +/** + * Category edit page. + */ +function login_destination_edit_form(&$form, &$form_state) { + // default values + $rule = $form_state['item']; + + $access = user_access('use PHP for settings'); + + $type = $rule->destination_type; + + if ($type == LOGIN_DESTINATION_SNIPPET && !$access) { + $form['destination_type'] = array( + '#type' => 'value', + '#value' => LOGIN_DESTINATION_SNIPPET, + ); + $form['destination'] = array( + '#type' => 'value', + '#value' => $rule->destination, + ); + } + else { + $options = array( + LOGIN_DESTINATION_STATIC => t('Internal page or external URL'), + ); + $description = t("Specify page by using its path. Example path is %blog for the blog page. %front is the front page. %current is the current page. Precede with http:// for an external URL. Leave empty to redirect to a default page.", array('%blog' => 'blog', '%front' => '', '%current' => '')); + + if (module_exists('php') && $access) { + $options += array(LOGIN_DESTINATION_SNIPPET => t('Page returned by this PHP code (experts only)')); + $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. It should return either a string value or an array of params that the %function function will understand, e.g. %example. For more information, see the online API entry for url function. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '', '%function' => 'url($path = \'\', array $options = array())', '%example' => ' \'overlay=admin/config\', ), ); ?>', '@url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url/7')); + } + + $form['destination_type'] = array( + '#type' => 'radios', + '#title' => 'Redirect to page', + '#default_value' => $type, + '#options' => $options, + ); + $form['destination'] = array( + '#type' => 'textarea', + '#default_value' => $rule->destination, + '#description' => $description, + ); + } + + $triggers = array_map('check_plain', $rule->triggers); + if (empty($triggers)) { + $triggers = array(); + } + + $form['triggers'] = array( + '#type' => 'checkboxes', + '#title' => t('Redirect upon triggers'), + '#options' => array('login' => 'Login, registration, one-time login link', 'logout' => 'Logout'), + '#default_value' => $triggers, + '#description' => 'Redirect only upon selected trigger(s). If you select no triggers, all of them will be used.', + ); + + $type = $rule->pages_type; + + if ($type == LOGIN_DESTINATION_REDIRECT_PHP && !$access) { + $form['pages_type'] = array( + '#type' => 'value', + '#value' => LOGIN_DESTINATION_REDIRECT_PHP, + ); + $form['pages'] = array( + '#type' => 'value', + '#value' => $rule->destination, + ); + } + else { + $options = array( + LOGIN_DESTINATION_REDIRECT_NOTLISTED => t('All pages except those listed'), + LOGIN_DESTINATION_REDIRECT_LISTED => t('Only the listed pages'), + ); + $description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. %login is the login form. %register is the registration form. %reset is the one-time login (e-mail validation).", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '', '%login' => 'user', '%register' => 'user/register', '%reset' => 'user/*/edit')); + + if (module_exists('php') && $access) { + $options += array(LOGIN_DESTINATION_REDIRECT_PHP => t('Pages on which this PHP code returns TRUE (experts only)')); + $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '')); + } + + $form['pages_type'] = array( + '#type' => 'radios', + '#title' => t('Redirect from specific pages'), + '#default_value' => $type, + '#options' => $options, + ); + $form['pages'] = array( + '#type' => 'textarea', + '#default_value' => $rule->pages, + '#description' => $description, + ); + } + + $default_role_options = array_map('check_plain', $rule->roles); + if (empty($default_role_options)) { + $default_role_options = array(); + } + + $form['roles'] = array( + '#type' => 'checkboxes', + '#title' => t('Redirect users with roles'), + '#options' => _login_destination_role_options(), + '#default_value' => $default_role_options, + '#description' => 'Redirect only the selected role(s). If you select no roles, all users will be redirected.', + ); + + $form['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight'), + '#default_value' => $rule->weight, + '#description' => t('When evaluating login destination rules, those with lighter (smaller) weights get evaluated before rules with heavier (larger) weights.'), + ); + + return $form; +}