Commit 774ef63c authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1765728 by dawehner, damiankloip: Cleanup methods on HandlerBase.

parent 69fa3f16
......@@ -107,7 +107,7 @@ <h3>Changed argument settings</h3>
),
</pre>
<h3>The introduction of get_value() and sanitize_value()</h3>
<h3>The introduction of get_value() and sanitizeValue()</h3>
The views_handler class got two new functions:
<pre>
/**
......@@ -133,7 +133,7 @@ <h3>The introduction of get_value() and sanitize_value()</h3>
* @param $type
* The type of sanitization needed. If not provided, check_plain() is used.
*/
function sanitize_value($value, $type = NULL) {
public function sanitizeValue($value, $type = NULL) {
switch ($type) {
case 'xss':
$value = filter_xss($value);
......@@ -158,7 +158,7 @@ <h3>The introduction of get_value() and sanitize_value()</h3>
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.
ways of sanitizing it, hence the usage of the sanitizeValue() function.
Examples of converting render() field handler implementations:
<pre>
......@@ -175,12 +175,12 @@ <h3>The introduction of get_value() and sanitize_value()</h3>
// Instead of this:
return check_plain($value);
// We write:
return $this->sanitize_value($value);
return $this->sanitizeValue($value);
// Since sanitize_value() supports different sanitization functions, this:
// Since sanitizeValue() supports different sanitization functions, this:
return filter_xss($value);
// Can become:
return $this->sanitize_value($value, 'xss');
return $this->sanitizeValue($value, 'xss');
</pre>
......
......@@ -2276,12 +2276,12 @@ function views_ui_edit_form_get_bucket($type, $view, $display) {
continue;
}
$field_name = check_plain($handler->ui_name(TRUE));
$field_name = check_plain($handler->uiName(TRUE));
if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
$field_name = '(' . $relationships[$field['relationship']] . ') ' . $field_name;
}
$description = filter_xss_admin($handler->admin_summary());
$description = filter_xss_admin($handler->adminSummary());
$link_text = $field_name . (empty($description) ? '' : " ($description)");
$link_attributes = array('class' => array('views-ajax-link'));
if (!empty($field['exclude'])) {
......@@ -2294,11 +2294,11 @@ function views_ui_edit_form_get_bucket($type, $view, $display) {
$build['fields'][$id]['#changed'] = TRUE;
}
if ($display->handler->useGroupBy() && $handler->use_group_by()) {
if ($display->handler->useGroupBy() && $handler->usesGroupBy()) {
$build['fields'][$id]['#settings_links'][] = l('<span class="label">' . t('Aggregation settings') . '</span>', "admin/structure/views/nojs/config-item-group/$view->name/$display->id/$type/$id", array('attributes' => array('class' => 'views-button-configure views-ajax-link', 'title' => t('Aggregation settings')), 'html' => TRUE));
}
if ($handler->has_extra_options()) {
if ($handler->hasExtraOptions()) {
$build['fields'][$id]['#settings_links'][] = l('<span class="label">' . t('Settings') . '</span>', "admin/structure/views/nojs/config-item-extra/$view->name/$display->id/$type/$id", array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => t('Settings')), 'html' => TRUE));
}
......@@ -3371,7 +3371,7 @@ function views_ui_rearrange_form($form, &$form_state) {
);
$handler = $display->handler->getHandler($type, $id);
if ($handler) {
$name = $handler->ui_name() . ' ' . $handler->admin_summary();
$name = $handler->uiName() . ' ' . $handler->adminSummary();
if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
$name = '(' . $relationships[$field['relationship']] . ') ' . $name;
}
......@@ -3726,7 +3726,7 @@ function views_ui_rearrange_filter_form($form, &$form_state) {
);
if ($handler) {
$name = $handler->ui_name() . ' ' . $handler->admin_summary();
$name = $handler->uiName() . ' ' . $handler->adminSummary();
if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
$name = '(' . $relationships[$field['relationship']] . ') ' . $name;
}
......@@ -4136,12 +4136,12 @@ function views_ui_add_item_form_submit($form, &$form_state) {
$key = $types[$type]['type'];
}
$handler = views_get_handler($table, $field, $key);
if ($form_state['view']->display_handler->useGroupBy() && $handler->use_group_by()) {
if ($form_state['view']->display_handler->useGroupBy() && $handler->usesGroupBy()) {
views_ui_add_form_to_stack('config-item-group', $form_state['view'], $form_state['display_id'], array($type, $id));
}
// check to see if this type has settings, if so add the settings form first
if ($handler && $handler->has_extra_options()) {
if ($handler && $handler->hasExtraOptions()) {
views_ui_add_form_to_stack('config-item-extra', $form_state['view'], $form_state['display_id'], array($type, $id));
}
// Then add the form to the stack
......@@ -4293,7 +4293,7 @@ function views_ui_config_item_form($form, &$form_state) {
);
}
$form['#title'] = t('Configure @type: @item', array('@type' => $types[$type]['lstitle'], '@item' => $handler->ui_name()));
$form['#title'] = t('Configure @type: @item', array('@type' => $types[$type]['lstitle'], '@item' => $handler->uiName()));
if (!empty($handler->definition['help'])) {
$form['options']['form_description'] = array(
......@@ -4476,9 +4476,9 @@ function views_ui_config_item_group_form($type, &$form_state) {
$handler->init($view, $item);
$types = View::viewsObjectTypes();
$form['#title'] = t('Configure group settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->ui_name()));
$form['#title'] = t('Configure group settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->uiName()));
$handler->groupby_form($form['options'], $form_state);
$handler->buildGroupByForm($form['options'], $form_state);
$form_state['handler'] = &$handler;
}
......@@ -4498,7 +4498,7 @@ function views_ui_config_item_group_form_submit($form, &$form_state) {
$handler = views_get_handler($item['table'], $item['field'], $type);
$handler->init($form_state['view'], $item);
$handler->groupby_form_submit($form, $form_state);
$handler->submitGroupByForm($form, $form_state);
// Store the item back on the view
$form_state['view']->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
......@@ -4534,7 +4534,7 @@ function views_ui_config_item_form_expose($form, &$form_state) {
// If necessary, set new defaults:
if ($item['exposed']) {
$form_state['handler']->expose_options();
$form_state['handler']->defaultExposeOptions();
}
$form_state['view']->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
......@@ -4577,12 +4577,12 @@ function views_ui_config_item_extra_form($form, &$form_state) {
$handler->init($view, $item);
$types = View::viewsObjectTypes();
$form['#title'] = t('Configure extra settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->ui_name()));
$form['#title'] = t('Configure extra settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->uiName()));
$form['#section'] = $display_id . '-' . $type . '-' . $id;
// Get form from the handler.
$handler->extra_options_form($form['options'], $form_state);
$handler->buildExtraOptionsForm($form['options'], $form_state);
$form_state['handler'] = &$handler;
}
......@@ -4595,7 +4595,7 @@ function views_ui_config_item_extra_form($form, &$form_state) {
* Validation handler for configing new item(s) to a view.
*/
function views_ui_config_item_extra_form_validate($form, &$form_state) {
$form_state['handler']->extra_options_validate($form['options'], $form_state);
$form_state['handler']->validateExtraOptionsForm($form['options'], $form_state);
}
/**
......@@ -4603,7 +4603,7 @@ function views_ui_config_item_extra_form_validate($form, &$form_state) {
*/
function views_ui_config_item_extra_form_submit($form, &$form_state) {
// Run it through the handler's submit function.
$form_state['handler']->extra_options_submit($form['options'], $form_state);
$form_state['handler']->submitExtraOptionsForm($form['options'], $form_state);
$item = $form_state['handler']->options;
// Store the data we're given.
......@@ -4648,7 +4648,7 @@ function views_ui_config_style_form($form, &$form_state) {
$handler->init($view, $item);
$types = View::viewsObjectTypes();
$form['#title'] = t('Configure summary style for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->ui_name()));
$form['#title'] = t('Configure summary style for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->uiName()));
$form['#section'] = $display_id . '-' . $type . '-style-options';
......
......@@ -46,7 +46,7 @@ public function buildOptionsForm(&$form, &$form_state) {
* it that option. If it wants us to do this, it must set $helper->formula = TRUE
* and implement handler->get_formula();
*/
function get_field() {
public function getField() {
if (!empty($this->formula)) {
return $this->handler->get_formula();
}
......@@ -68,7 +68,7 @@ function add_table($join = NULL, $alias = NULL) {
$field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field;
if (empty($join)) {
$join = $this->get_join();
$join = $this->getJoin();
}
// See if there's a chain between us and the base relationship. If so, we need
......@@ -109,8 +109,8 @@ function add_table($join = NULL, $alias = NULL) {
return $alias;
}
function get_join() {
return $this->handler->get_join();
public function getJoin() {
return $this->handler->getJoin();
}
/**
......@@ -119,7 +119,7 @@ function get_join() {
*/
function summary_join() {
$field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field;
$join = $this->get_join();
$join = $this->getJoin();
// shortcuts
$options = $this->handler->options;
......@@ -151,10 +151,10 @@ function summary_join() {
}
/**
* Override ensure_my_table so we can control how this joins in.
* Override ensureMyTable so we can control how this joins in.
* The operator actually has influence over joining.
*/
function ensure_my_table() {
public function ensureMyTable() {
if (!isset($this->handler->table_alias)) {
// Case 1: Operator is an 'or' and we're not reducing duplicates.
// We hence get the absolute simplest:
......@@ -163,7 +163,7 @@ function ensure_my_table() {
if (empty($this->handler->options['add_table']) && empty($this->handler->view->many_to_one_tables[$field])) {
// query optimization, INNER joins are slightly faster, so use them
// when we know we can.
$join = $this->get_join();
$join = $this->getJoin();
if (isset($join)) {
$join->type = 'INNER';
}
......@@ -171,7 +171,7 @@ function ensure_my_table() {
$this->handler->view->many_to_one_tables[$field] = $this->handler->value;
}
else {
$join = $this->get_join();
$join = $this->getJoin();
$join->type = 'LEFT';
if (!empty($this->handler->view->many_to_one_tables[$field])) {
foreach ($this->handler->view->many_to_one_tables[$field] as $value) {
......@@ -198,7 +198,7 @@ function ensure_my_table() {
// Clone the join for each table:
$this->handler->table_aliases = array();
foreach ($this->handler->value as $value) {
$join = $this->get_join();
$join = $this->getJoin();
if ($this->handler->operator == 'and') {
$join->type = 'INNER';
}
......@@ -230,7 +230,7 @@ function ensure_my_table() {
// We just do one join. We'll add a where clause during
// the query phase to ensure that $table.$field IS NULL.
else {
$join = $this->get_join();
$join = $this->getJoin();
$join->type = 'LEFT';
$join->extra = array();
$join->extra_type = 'OR';
......@@ -251,7 +251,7 @@ function ensure_my_table() {
/**
* Provides a unique placeholders for handlers.
*/
function placeholder() {
protected function placeholder() {
return $this->handler->query->placeholder($this->handler->options['table'] . '_' . $this->handler->options['field']);
}
......@@ -259,10 +259,10 @@ function add_filter() {
if (empty($this->handler->value)) {
return;
}
$this->handler->ensure_my_table();
$this->handler->ensureMyTable();
// Shorten some variables:
$field = $this->get_field();
$field = $this->getField();
$options = $this->handler->options;
$operator = $this->handler->operator;
$formula = !empty($this->formula);
......
......@@ -78,7 +78,7 @@ abstract class HandlerBase extends PluginBase {
* The item from the database; the actual contents of this will vary
* based upon the type of handler.
*/
function init(&$view, &$options) {
public function init(&$view, &$options) {
$this->view = &$view;
$display_id = $this->view->current_display;
// Check to see if this handler type is defaulted. Note that
......@@ -143,7 +143,7 @@ protected function defineOptions() {
$options['field'] = array('default' => '');
$options['relationship'] = array('default' => 'none');
$options['group_type'] = array('default' => 'group');
$options['ui_name'] = array('default' => '');
$options['ui_name'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
......@@ -151,7 +151,7 @@ protected function defineOptions() {
/**
* Return a string representing this handler's name in the UI.
*/
function ui_name($short = FALSE) {
public function uiName($short = FALSE) {
if (!empty($this->options['ui_name'])) {
$title = check_plain($this->options['ui_name']);
return $title;
......@@ -165,9 +165,9 @@ function ui_name($short = FALSE) {
*
* This should be overridden for handlers with formulae or other
* non-standard fields. Because this takes an argument, fields
* overriding this can just call return parent::get_field($formula)
* overriding this can just call return parent::getField($formula)
*/
function get_field($field = NULL) {
public function getField($field = NULL) {
if (!isset($field)) {
if (!empty($this->formula)) {
$field = $this->get_formula();
......@@ -205,7 +205,7 @@ function get_field($field = NULL) {
* @return string
* Returns the safe value.
*/
function sanitize_value($value, $type = NULL) {
protected function sanitizeValue($value, $type = NULL) {
switch ($type) {
case 'xss':
$value = filter_xss($value);
......@@ -238,7 +238,7 @@ function sanitize_value($value, $type = NULL) {
* @return string
* The transformed string.
*/
function case_transform($string, $option) {
protected function caseTransform($string, $option) {
global $multibyte;
switch ($option) {
......@@ -305,13 +305,13 @@ public function submitOptionsForm(&$form, &$form_state) { }
/**
* Provides the handler some groupby.
*/
function use_group_by() {
public function usesGroupBy() {
return TRUE;
}
/**
* Provide a form for aggregation settings.
*/
function groupby_form(&$form, &$form_state) {
public function buildGroupByForm(&$form, &$form_state) {
$view = &$form_state['view'];
$display_id = $form_state['display_id'];
$types = View::viewsObjectTypes();
......@@ -319,7 +319,7 @@ function groupby_form(&$form, &$form_state) {
$id = $form_state['id'];
$form['#title'] = check_plain($view->display[$display_id]->display_title) . ': ';
$form['#title'] .= t('Configure aggregation settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $this->ui_name()));
$form['#title'] .= t('Configure aggregation settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $this->uiName()));
$form['#section'] = $display_id . '-' . $type . '-' . $id;
......@@ -342,7 +342,7 @@ function groupby_form(&$form, &$form_state) {
* Perform any necessary changes to the form values prior to storage.
* There is no need for this function to actually store the data.
*/
function groupby_form_submit(&$form, &$form_state) {
public function submitGroupByForm(&$form, &$form_state) {
$item =& $form_state['handler']->options;
$item['group_type'] = $form_state['values']['options']['group_type'];
......@@ -352,90 +352,90 @@ function groupby_form_submit(&$form, &$form_state) {
* If a handler has 'extra options' it will get a little settings widget and
* another form called extra_options.
*/
function has_extra_options() { return FALSE; }
public function hasExtraOptions() { return FALSE; }
/**
* Provide defaults for the handler.
*/
function extra_options(&$option) { }
public function defineExtraOptions(&$option) { }
/**
* Provide a form for setting options.
*/
function extra_options_form(&$form, &$form_state) { }
public function buildExtraOptionsForm(&$form, &$form_state) { }
/**
* Validate the options form.
*/
function extra_options_validate($form, &$form_state) { }
public function validateExtraOptionsForm($form, &$form_state) { }
/**
* Perform any necessary changes to the form values prior to storage.
* There is no need for this function to actually store the data.
*/
function extra_options_submit($form, &$form_state) { }
public function submitExtraOptionsForm($form, &$form_state) { }
/**
* Determine if a handler can be exposed.
*/
function can_expose() { return FALSE; }
public function canExpose() { return FALSE; }
/**
* Set new exposed option defaults when exposed setting is flipped
* on.
*/
function expose_options() { }
public function defaultExposeOptions() { }
/**
* Get information about the exposed form for the form renderer.
*/
function exposed_info() { }
public function exposedInfo() { }
/**
* Render our chunk of the exposed handler form when selecting
*/
function exposed_form(&$form, &$form_state) { }
public function buildExposedForm(&$form, &$form_state) { }
/**
* Validate the exposed handler form
*/
function exposed_validate(&$form, &$form_state) { }
public function validateExposed(&$form, &$form_state) { }
/**
* Submit the exposed handler form
*/
function exposed_submit(&$form, &$form_state) { }
public function submitExposed(&$form, &$form_state) { }
/**
* Form for exposed handler options.
*/
function expose_form(&$form, &$form_state) { }
public function buildExposeForm(&$form, &$form_state) { }
/**
* Validate the options form.
*/
function expose_validate($form, &$form_state) { }
public function validateExposeForm($form, &$form_state) { }
/**
* Perform any necessary changes to the form exposes prior to storage.
* There is no need for this function to actually store the data.
*/
function expose_submit($form, &$form_state) { }
public function submitExposeForm($form, &$form_state) { }
/**
* Shortcut to display the expose/hide button.
*/
function show_expose_button(&$form, &$form_state) { }
public function showExposeButton(&$form, &$form_state) { }
/**
* Shortcut to display the exposed options form.
*/
function show_expose_form(&$form, &$form_state) {
public function showExposeForm(&$form, &$form_state) {
if (empty($this->options['exposed'])) {
return;
}
$this->expose_form($form, $form_state);
$this->buildExposeForm($form, $form_state);
// When we click the expose button, we add new gadgets to the form but they
// have no data in $_POST so their defaults get wiped out. This prevents
......@@ -455,7 +455,7 @@ function show_expose_form(&$form, &$form_state) {
*
* @return boolean
*/
function access() {
public function access() {
if (isset($this->definition['access callback']) && function_exists($this->definition['access callback'])) {
if (isset($this->definition['access arguments']) && is_array($this->definition['access arguments'])) {
return call_user_func_array($this->definition['access callback'], $this->definition['access arguments']);
......@@ -472,7 +472,7 @@ function access() {
* This gives all the handlers some time to set up before any handler has
* been fully run.
*/
function pre_query() { }
public function preQuery() { }
/**
* Run after the view is executed, before the result is cached.
......@@ -481,12 +481,12 @@ function pre_query() { }
* used so that handlers that pull up secondary data can put it in the
* $values so that the raw data can be utilized externally.
*/
function post_execute(&$values) { }
public function postExecute(&$values) { }
/**
* Provides a unique placeholders for handlers.
*/
function placeholder() {
protected function placeholder() {
return $this->query->placeholder($this->options['table'] . '_' . $this->options['field']);
}
......@@ -494,7 +494,7 @@ function placeholder() {
* Called just prior to query(), this lets a handler set up any relationship
* it needs.
*/
function set_relationship() {
public function setRelationship() {
// Ensure this gets set to something.
$this->relationship = NULL;
......@@ -524,7 +524,7 @@ function set_relationship() {
* Ensure the main table for this handler is in the query. This is used
* a lot.
*/
function ensure_my_table() {
public function ensureMyTable() {
if (!isset($this->table_alias)) {
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship);
}
......@@ -534,14 +534,14 @@ function ensure_my_table() {
/**
* Provide text for the administrative summary
*/
function admin_summary() { }
public function adminSummary() { }
/**
* Determine if the argument needs a style plugin.
*
* @return TRUE/FALSE
*/
function needs_style_plugin() { return FALSE; }
public function needsStylePlugin() { return FALSE; }
/**
* Determine if this item is 'exposed', meaning it provides form elements
......@@ -549,31 +549,31 @@ function needs_style_plugin() { return FALSE; }
*
* @return TRUE/FALSE
*/
function is_exposed() {
public function isExposed() {
return !empty($this->options['exposed']);
}
/**
* Returns TRUE if the exposed filter works like a grouped filter.
*/
function is_a_group() { return FALSE; }