In order to take advantage of the changes in Drupal 7, Views has gone through several API changes. Here's what you should know.
name = Example module description = "Gives an example of a module." core = 7.x files[] = example.module files[] = example.install ; Views handlers files[] = includes/views/handlers/example_handler_argument_string.inc
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . $this->operator . " '%s'", $this->value);has to be converted to
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", $this->value, $this->operator);If your field is a complex where condition:
$this->query->add_where($this->options['group'], "$upper($field) NOT LIKE $upper('%%%s')", $this->value);has to be converted to
$placeholder = $this->placeholder(); $this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => '%' . db_like($this->value)));placeholder() generates a automatic unique placeholder for you. add_where with operator 'formula' can be converted to add_where_expression. add_having with operator 'formula' can be converted to add_having_expression.
$categories['block'] = array( 'title' => t('Block settings'), 'column' => 'second', 'build' => array( '#weight' => -10, ), );
$this->options['exception']['value'] = $options['wildcard']; $this->options['exception']['title'] = $options['wildcard_substitution'];3. Summary plugin options are now stored in 'summary_options' instead of 'style_options'
$this->options['summary_options'] = $options['style_options'];4. The selected summary plugin is no longer stored in 'style_plugin'.
$this->options['summary']['format'] = $options['style_plugin'];5. The validator options have been moved.
$options['validate']['type'] = $options['validate_type']; $options['validate']['fail'] = $options['validate_fail'];6. The validator settings have been moved from $form['argument_validate'] to ['validate_options'] This means that dependent code in validate plugins needs to change. Example change for views_plugin_argument_validate_user:
$form['roles'] = array( '#dependency' => array( - 'edit-options-argument-validate-user-restrict-roles' => array(1), + 'edit-options-validate-options-user-restrict-roles' => array(1), ),
/** * Get the value that's supposed to be rendered. * * @param object $values * An object containing all retrieved values. * @param string $field * Optional name of the field where the value is stored. */ function get_value($values, $field = NULL) { $alias = isset($field) ? $this->aliases[$field] : $this->field_alias; if (isset($values->{$alias})) { return $values->{$alias}; } } /** * Sanitize the value for output. * * @param string $value * The value being rendered. * @param string $type * The type of sanitization needed. If not provided, check_plain() is used. */ function sanitize_value($value, $type = NULL) { switch ($type) { case 'xss': $value = filter_xss($value); break; case 'url': $value = check_url($value); break; default: $value = check_plain($value); break; } return $value; }These functions are meant to be used in the render() functions of field handlers, for fetching data (usually by alias) from the $values object, and for sanitizing values. The abstraction of fetching data from rendering data is important because different query backends have different ways of storing data in $values, and the field alias is a SQL specific thing. So instead of overriding the whole render() function and copying all of the logic there (as well as having to constantly keep up with upstream Views changes), the backend can just override get_values(), which is significantly less code. Of course, different ways of fetching and displaying data might require different ways of sanitizing it, hence the usage of the sanitize_value() function. Examples of converting render() field handler implementations:
// This $value = $values->{$this->field_alias}; // Becomes this $value = $this->get_value($values); // And this $format = $values->{$this->aliases['format']}; // Becomes this $format = $this->get_values($values, 'format'); // Instead of this: return check_plain($value); // We write: return $this->sanitize_value($value); // Since sanitize_value() supports different sanitization functions, this: return filter_xss($value); // Can become: return $this->sanitize_value($value, 'xss');
array ( {grouping value} => array( 'group' => {rendered_value of the grouping field}, 'rows' => array({group rows}), ), );
array ( {rendered_value of the grouping field} => array({group rows}), );