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);
......
......@@ -30,7 +30,7 @@ abstract class AccessPluginBase extends PluginBase {
* @param $display
* The display handler.
*/
function init(&$view, &$display) {
public function init(&$view, &$display) {
$this->view = &$view;
$this->display = &$display;
......@@ -73,7 +73,7 @@ public function summaryTitle() {
/**
* Determine if the current user has access or not.
*/
function access($account) {
public function access($account) {
// default to no access control.
return TRUE;
}
......
......@@ -28,7 +28,7 @@ class Permission extends AccessPluginBase {
*/
protected $usesOptions = TRUE;
function access($account) {
public function access($account) {
return views_check_perm($this->options['perm'], $account);
}
......
......@@ -28,7 +28,7 @@ class Role extends AccessPluginBase {
*/
protected $usesOptions = TRUE;
function access($account) {
public function access($account) {
return views_check_roles(array_filter($this->options['role']), $account);
}
......
......@@ -30,7 +30,7 @@ abstract class AreaPluginBase extends HandlerBase {
* Make sure that no result area handlers are set to be shown when the result
* is empty.
*/
function init(&$view, &$options) {
public function init(&$view, &$options) {
parent::init($view, $options);
if ($this->handler_type == 'empty') {
$this->options['empty'] = TRUE;
......@@ -38,9 +38,9 @@ function init(&$view, &$options) {
}
/**
* Get this field's label.
* Get this area's label.
*/
function label() {
public function label() {
if (!isset($this->options['label'])) {
return $this->ui_name();
}
......@@ -61,7 +61,7 @@ protected function defineOptions() {
/**
* Provide extra data to the administration form
*/
function admin_summary() {
public function adminSummary() {
return $this->label();
}
......@@ -78,6 +78,7 @@ public function buildOptionsForm(&$form, &$form_state) {
'#description' => t('The label for this area that will be displayed only administratively.'),
);
if ($form_state['type'] != 'empty') {
$form['empty'] = array(
'#type' => 'checkbox',
......@@ -102,7 +103,7 @@ function render($empty = FALSE) {
/**
* Area handlers shouldn't have groupby.
*/
function use_group_by() {
public function usesGroupBy() {
return FALSE;
}
......
......@@ -20,11 +20,11 @@
*/
class Broken extends AreaPluginBase {
function ui_name($short = FALSE) {
public function uiName($short = FALSE) {
return t('Broken/missing handler');
}
function ensure_my_table() { /* No table to ensure! */ }
public function ensureMyTable() { /* No table to ensure! */ }
public function query($group_by = FALSE) { /* No query to run */ }
function render($empty = FALSE) { return ''; }
public function buildOptionsForm(&$form, &$form_state) {
......@@ -36,7 +36,7 @@ public function buildOptionsForm(&$form, &$form_state) {
/**
* Determine if the handler is considered 'broken'
*/
function broken() {
public function broken() {
return TRUE;
}
......
......@@ -49,13 +49,13 @@ public function buildOptionsForm(&$form, &$form_state) {
// Get a list of the available fields and arguments for token replacement.
$options = array();
foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) {
$options[t('Fields')]["[$field]"] = $handler->ui_name();
$options[t('Fields')]["[$field]"] = $handler->uiName();
}
$count = 0; // This lets us prepare the key as we want it printed.
foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->uiName()));
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->uiName()));
}
if (!empty($options)) {
......
......@@ -55,7 +55,7 @@ function render_textarea_custom($value) {
if ($this->options['tokenize']) {
$value = $this->view->style_plugin->tokenize_value($value, 0);
}
return $this->sanitize_value($value, 'xss_admin');
return $this->sanitizeValue($value, 'xss_admin');
}
}
......
......@@ -113,7 +113,7 @@ function exception_title() {
*
* @return TRUE/FALSE
*/
function needs_style_plugin() {
public function needsStylePlugin() {
$info = $this->default_actions($this->options['default_action']);
$validate_info = $this->default_actions($this->options['validate']['fail']);
return !empty($info['style plugin']) || !empty($validate_info['style plugin']);
......@@ -802,7 +802,7 @@ function default_summary() {
* The alias used to get the number of records (count) for this entry.
*/
function summary_query() {
$this->ensure_my_table();
$this->ensureMyTable();
// Add the field.
$this->base_alias = $this->query->add_field($this->table_alias, $this->real_field);
......@@ -907,7 +907,7 @@ function summary_name($data) {
* The argument sent may be found at $this->argument.
*/
public function query($group_by = FALSE) {
$this->ensure_my_table();
$this->ensureMyTable();
$this->query->add_where(0, "$this->table_alias.$this->real_field", $this->argument);
}
......
......@@ -20,11 +20,11 @@
*/
class Broken extends ArgumentPluginBase {
function ui_name($short = FALSE) {
public function uiName($short = FALSE) {
return t('Broken/missing handler');
}
function ensure_my_table() { /* No table to ensure! */ }
public function ensureMyTable() { /* No table to ensure! */ }
public function query($group_by = FALSE) { /* No query to run */ }
public function buildOptionsForm(&$form, &$form_state) {
$form['markup'] = array(
......@@ -35,6 +35,6 @@ public function buildOptionsForm(&$form, &$form_state) {
/**
* Determine if the handler is considered 'broken'
*/
function broken() { return TRUE; }
public function broken() { return TRUE; }
}
......@@ -46,7 +46,7 @@ function get_formula() {
* Build the summary query based on a formula
*/
function summary_query() {
$this->ensure_my_table();
$this->ensureMyTable();
// Now that our table is secure, get our formula.
$formula = $this->get_formula();
......@@ -61,7 +61,7 @@ function summary_query() {
* Build the query based upon the formula
*/
public function query($group_by = FALSE) {
$this->ensure_my_table();
$this->ensureMyTable();
// Now that our table is secure, get our formula.
$placeholder = $this->placeholder();
$formula = $this->get_formula() .' = ' . $placeholder;
......
......@@ -21,15 +21,15 @@
class GroupByNumeric extends ArgumentPluginBase {
public function query($group_by = FALSE) {
$this->ensure_my_table();
$field = $this->get_field();
$this->ensureMyTable();
$field = $this->getField();
$placeholder = $this->placeholder();
$this->query->add_having_expression(0, "$field = $placeholder", array($placeholder => $this->argument));
}
function ui_name($short = FALSE) {
return $this->get_field(parent::ui_name($short));
public function uiName($short = FALSE) {
return $this->getField(parent::uiName($short));
}
function get_sort_name() {
......
......@@ -29,7 +29,7 @@
*/
class ManyToOne extends ArgumentPluginBase {
function init(&$view, &$options) {
public function init(&$view, &$options) {
parent::init($view, $options);
$this->helper = new ManyToOneHelper($this);
......@@ -90,11 +90,11 @@ public function buildOptionsForm(&$form, &$form_state) {
}
/**
* 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() {
$this->helper->ensure_my_table();
public function ensureMyTable() {
$this->helper->ensureMyTable();
}
public function query($group_by = FALSE) {
......@@ -110,7 +110,7 @@ public function query($group_by = FALSE) {
}
}
if ($empty) {
parent::ensure_my_table();
parent::ensureMyTable();
$this->query->add_where(0, "$this->table_alias.$this->real_field", NULL, 'IS NULL');
return;
}
......@@ -159,7 +159,7 @@ function title() {
function summary_query() {
$field = $this->table . '.' . $this->field;
$join = $this->get_join();
$join = $this->getJoin();
if (!empty($this->options['require_value'])) {
$join->type = 'INNER';
......
......@@ -97,7 +97,7 @@ function title_query() {
}
public function query($group_by = FALSE) {
$this->ensure_my_table();
$this->ensureMyTable();
if (!empty($this->options['break_phrase'])) {
views_break_phrase($this->argument, $this);
......
......@@ -22,7 +22,7 @@
*/
class String extends ArgumentPluginBase {
function init(&$view, &$options) {
public function init(&$view, &$options) {
parent::init($view, $options);
if (!empty($this->definition['many to one'])) {
$this->helper = new ManyToOneHelper($this);
......@@ -144,7 +144,7 @@ public function buildOptionsForm(&$form, &$form_state) {
*/
function summary_query() {
if (empty($this->definition['many to one'])) {
$this->ensure_my_table();
$this->ensureMyTable();
}
else {
$this->table_alias = $this->helper->summary_join();
......@@ -169,7 +169,7 @@ function summary_query() {
/**
* Get the formula for this argument.