Projet

Général

Profil

Paste
Télécharger (4,71 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / link / views / link_views_handler_argument_target.inc @ bad4e148

1
<?php
2

    
3
/**
4
 * @file
5
 * Argument handler to filter results by target.
6
 */
7

    
8
/**
9
 * Argument handler to filter results by target.
10
 *
11
 * @codingStandardsIgnoreStart
12
 */
13
class link_views_handler_argument_target extends views_handler_argument {
14

    
15
  /**
16
   * Provide defaults for the argument when a new one is created.
17
   */
18
  function option_definition() {
19
    $options = parent::option_definition();
20

    
21
    return $options;
22
  }
23
  /**
24
   * Provide a default options form for the argument.
25
   *
26
   * @codingStandardsIgnoreStart
27
   */
28
  public function options_form(&$form, &$form_state) {
29
    // @codingStandardsIgnoreEnd
30
    $defaults = $this->default_actions();
31

    
32
    $form['title'] = array(
33
      '#prefix' => '<div class="clear-block">',
34
      '#suffix' => '</div>',
35
      '#type' => 'textfield',
36
      '#title' => t('Title'),
37
      '#default_value' => $this->options['title'],
38
      '#description' => t('The title to use when this argument is present; it will override the title of the view and titles from previous arguments. You can use percent substitution here to replace with argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
39
    );
40

    
41
    $form['clear_start'] = array(
42
      '#value' => '<div class="clear-block">',
43
    );
44

    
45
    $form['defaults_start'] = array(
46
      '#value' => '<div class="views-left-50">',
47
    );
48

    
49
    $form['default_action'] = array(
50
      '#type' => 'radios',
51
      '#title' => t('Action to take if argument is not present'),
52
      '#default_value' => $this->options['default_action'],
53
    );
54

    
55
    $form['defaults_stop'] = array(
56
      '#value' => '</div>',
57
    );
58

    
59
    $form['wildcard'] = array(
60
      '#prefix' => '<div class="views-right-50">',
61
      // Prefix and no suffix means these two items will be grouped together.
62
      '#type' => 'textfield',
63
      '#title' => t('Wildcard'),
64
      '#size' => 20,
65
      '#default_value' => $this->options['wildcard'],
66
      '#description' => t('If this value is received as an argument, the argument will be ignored; i.e, "all values"'),
67
    );
68

    
69
    $form['wildcard_substitution'] = array(
70
      '#suffix' => '</div>',
71
      '#type' => 'textfield',
72
      '#title' => t('Wildcard title'),
73
      '#size' => 20,
74
      '#default_value' => $this->options['wildcard_substitution'],
75
      '#description' => t('The title to use for the wildcard in substitutions elsewhere.'),
76
    );
77

    
78
    $form['clear_stop'] = array(
79
      '#value' => '</div>',
80
    );
81

    
82
    $options = array();
83
    $validate_options = array();
84
    foreach ($defaults as $id => $info) {
85
      $options[$id] = $info['title'];
86
      if (empty($info['default only'])) {
87
        $validate_options[$id] = $info['title'];
88
      }
89
      if (!empty($info['form method'])) {
90
        $this->{$info['form method']}($form, $form_state);
91
      }
92
    }
93

    
94
    $form['default_action']['#options'] = $options;
95

    
96
    $form['validate_type'] = array(
97
      '#type' => 'select',
98
      '#title' => t('Validator'),
99
      '#default_value' => $this->options['validate_type'],
100
    );
101

    
102
    $validate_types = array('none' => t('- Basic validation -'));
103
    $plugins = views_fetch_plugin_data('argument validator');
104
    foreach ($plugins as $id => $info) {
105
      $valid = TRUE;
106
      if (!empty($info['type'])) {
107
        $valid = FALSE;
108
        if (empty($this->definition['validate type'])) {
109
          continue;
110
        }
111
        foreach ((array) $info['type'] as $type) {
112
          if ($type == $this->definition['validate type']) {
113
            $valid = TRUE;
114
            break;
115
          }
116
        }
117
      }
118

    
119
      // If we decide this validator is ok, add it to the list.
120
      if ($valid) {
121
        $plugin = views_get_plugin('argument validator', $id);
122
        if ($plugin) {
123
          $plugin->init($this->view, $this, $id);
124
          if ($plugin->access()) {
125
            $plugin->validate_form($form, $form_state, $id);
126
            $validate_types[$id] = $info['title'];
127
          }
128
        }
129
      }
130
    }
131

    
132
    asort($validate_types);
133
    $form['validate_type']['#options'] = $validate_types;
134

    
135
    // Show this gadget if *anything* but 'none' is selected.
136
    $form['validate_fail'] = array(
137
      '#type' => 'select',
138
      '#title' => t('Action to take if argument does not validate'),
139
      '#default_value' => $this->options['validate_fail'],
140
      '#options' => $validate_options,
141
    );
142
  }
143

    
144
  /**
145
   * Set up the query for this argument.
146
   *
147
   * The argument sent may be found at $this->argument.
148
   */
149
  public function query($group_by = FALSE) {
150
    $this->ensure_my_table();
151
    // Because attributes are stored serialized, our only option is to also
152
    // serialize the data we're searching for and use LIKE to find similar data.
153
    $this->query->add_where(0, $this->table_alias . ' . ' . $this->real_field . " LIKE '%%%s%'", serialize(array('target' => $this->argument)));
154
  }
155

    
156
}