Conjunto de cambios 59029b2 en sipes para modules_contrib/views/modules/user/views_plugin_argument_validate_user.inc
- Fecha y hora:
- 26/05/2016 14:17:08 (hace 8 años)
- Branches:
- stable, version-3.0
- Children:
- 32a0eb4
- Parents:
- b907fa2
- Fichero:
-
- 1 editado
Leyenda
- No modificado
- Añadido
- Eliminado
-
modules_contrib/views/modules/user/views_plugin_argument_validate_user.inc
r177a560 r59029b2 9 9 */ 10 10 class views_plugin_argument_validate_user extends views_plugin_argument_validate { 11 function validate_form(&$form, &$form_state) { 12 // We are unable to rely on options having already been set, so let's make 13 // sure defaults are here: 14 if (!isset($this->argument->options['validate_user_argument_type'])) { 15 $this->argument->options['validate_user_argument_type'] = 'uid'; 16 $this->argument->options['validate_user_roles'] = array(); 17 } 11 function option_definition() { 12 $options = parent::option_definition(); 13 $options['type'] = array('default' => 'uid'); 14 $options['restrict_roles'] = array('default' => FALSE); 15 $options['roles'] = array('default' => array()); 18 16 19 $form['validate_user_argument_type'] = array( 17 return $options; 18 } 19 20 function options_form(&$form, &$form_state) { 21 $form['type'] = array( 20 22 '#type' => 'radios', 21 23 '#title' => t('Type of user argument to allow'), … … 25 27 'either' => t('Allow both numeric UIDs and string usernames'), 26 28 ), 27 '#default_value' => $this->argument->options['validate_user_argument_type'], 28 '#process' => array('expand_radios', 'views_process_dependency'), 29 '#dependency' => array('edit-options-validate-type' => array($this->id)), 30 '#prefix' => '<div id="edit-options-validate-user-argument-type-wrapper">', 31 '#suffix' => '</div>', 29 '#default_value' => $this->options['type'], 32 30 ); 33 31 34 $form[' validate_user_restrict_roles'] = array(32 $form['restrict_roles'] = array( 35 33 '#type' => 'checkbox', 36 34 '#title' => t('Restrict user based on role'), 37 '#default_value' => !empty($this->argument->options['validate_user_restrict_roles']), 38 '#process' => array('views_process_dependency'), 39 '#dependency' => array('edit-options-validate-type' => array($this->id)), 35 '#default_value' => $this->options['restrict_roles'], 40 36 ); 41 37 42 $form[' validate_user_roles'] = array(38 $form['roles'] = array( 43 39 '#type' => 'checkboxes', 44 '#prefix' => '<div id="edit-options- validate-user-roles-wrapper">',40 '#prefix' => '<div id="edit-options-argument-validate-user-roles-wrapper">', 45 41 '#suffix' => '</div>', 46 42 '#title' => t('Restrict to the selected roles'), 47 43 '#options' => user_roles(TRUE), 48 '#default_value' => $this-> argument->options['validate_user_roles'],44 '#default_value' => $this->options['roles'], 49 45 '#description' => t('If no roles are selected, users from any role will be allowed.'), 50 46 '#process' => array('expand_checkboxes', 'views_process_dependency'), 51 47 '#dependency' => array( 52 'edit-options-validate-type' => array($this->id), 53 'edit-options-validate-user-restrict-roles' => array(1), 48 'edit-options-argument-validate-user-restrict-roles' => array(1), 54 49 ), 55 '#dependency_count' => 2,56 50 ); 57 51 } 58 52 53 function options_submit($form, &$form_state, &$options) { 54 // filter trash out of the options so we don't store giant unnecessary arrays 55 $options['roles'] = array_filter($options['roles']); 56 } 57 58 function convert_options(&$options) { 59 if (!isset($options['type']) && isset($this->argument->options['validate_user_argument_type'])) { 60 $options['type'] = $this->argument->options['validate_user_argument_type']; 61 $options['restrict_roles'] = $this->argument->options['validate_user_restrict_roles']; 62 $options['roles'] = $this->argument->options['validate_user_roles']; 63 } 64 } 65 59 66 function validate_argument($argument) { 60 $type = $this-> argument->options['validate_user_argument_type'];67 $type = $this->options['type']; 61 68 // is_numeric() can return false positives, so we ensure it's an integer. 62 69 // However, is_integer() will always fail, since $argument is a string. … … 97 104 98 105 // See if we're filtering users based on roles. 99 if (!empty($this-> argument->options['validate_user_restrict_roles']) && !empty($this->argument->options['validate_user_roles'])) {100 $roles = $this-> argument->options['validate_user_roles'];106 if (!empty($this->options['restrict_roles']) && !empty($this->options['roles'])) { 107 $roles = $this->options['roles']; 101 108 $account->roles = array(); 102 109 $account->roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID; … … 105 112 $account->roles[] = $role->rid; 106 113 } 107 if (!(bool) array_intersect($account->roles, $roles)) {114 if (!(bool) array_intersect($account->roles, $roles)) { 108 115 return FALSE; 109 116 } … … 111 118 112 119 $this->argument->argument = $account->uid; 113 $this->argument->validated_title = check_plain($account->name);120 $this->argument->validated_title = isset($account->name) ? check_plain($account->name) : check_plain(variable_get('anonymous', t('Anonymous'))); 114 121 return TRUE; 115 122 } 116 123 } 117
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.