Ignorar:
Fecha y hora:
26/05/2016 14:17:08 (hace 8 años)
Autor:
José Gregorio Puentes <jpuentes@…>
Branches:
stable, version-3.0
Children:
32a0eb4
Parents:
b907fa2
Mensaje:

se actualizo la version del modulo views

Fichero:
1 editado

Leyenda

No modificado
Añadido
Eliminado
  • modules_contrib/views/modules/user/views_plugin_argument_validate_user.inc

    r177a560 r59029b2  
    99 */
    1010class 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());
    1816
    19     $form['validate_user_argument_type'] = array(
     17    return $options;
     18  }
     19
     20  function options_form(&$form, &$form_state) {
     21    $form['type'] = array(
    2022      '#type' => 'radios',
    2123      '#title' => t('Type of user argument to allow'),
     
    2527        'either' => t('Allow both numeric UIDs and string usernames'),
    2628      ),
    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'],
    3230    );
    3331
    34     $form['validate_user_restrict_roles'] = array(
     32    $form['restrict_roles'] = array(
    3533      '#type' => 'checkbox',
    3634      '#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'],
    4036    );
    4137
    42     $form['validate_user_roles'] = array(
     38    $form['roles'] = array(
    4339      '#type' => 'checkboxes',
    44       '#prefix' => '<div id="edit-options-validate-user-roles-wrapper">',
     40      '#prefix' => '<div id="edit-options-argument-validate-user-roles-wrapper">',
    4541      '#suffix' => '</div>',
    4642      '#title' => t('Restrict to the selected roles'),
    4743      '#options' => user_roles(TRUE),
    48       '#default_value' => $this->argument->options['validate_user_roles'],
     44      '#default_value' => $this->options['roles'],
    4945      '#description' => t('If no roles are selected, users from any role will be allowed.'),
    5046      '#process' => array('expand_checkboxes', 'views_process_dependency'),
    5147      '#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),
    5449      ),
    55       '#dependency_count' => 2,
    5650    );
    5751  }
    5852
     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
    5966  function validate_argument($argument) {
    60     $type = $this->argument->options['validate_user_argument_type'];
     67    $type = $this->options['type'];
    6168    // is_numeric() can return false positives, so we ensure it's an integer.
    6269    // However, is_integer() will always fail, since $argument is a string.
     
    97104
    98105    // 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'];
    101108      $account->roles = array();
    102109      $account->roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
     
    105112        $account->roles[] = $role->rid;
    106113      }
    107       if (!(bool)array_intersect($account->roles, $roles)) {
     114      if (!(bool) array_intersect($account->roles, $roles)) {
    108115        return FALSE;
    109116      }
     
    111118
    112119    $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')));
    114121    return TRUE;
    115122  }
    116123}
    117 
Nota: Vea TracChangeset para ayuda en el uso del visor de conjuntos de cambios.