Commit acbb3bcf authored by tim.plunkett's avatar tim.plunkett
Browse files

Issue #1748118 by dawehner, tim.plunkett: Remove update code in init() methods.

parent 8fd8d393
......@@ -74,68 +74,6 @@ function construct() {
}
}
function init(&$view, &$options) {
parent::init($view, $options);
// Compatibility: The new UI changed several settings.
if (!empty($options['wildcard']) && !isset($options['exception']['value'])) {
$this->options['exception']['value'] = $options['wildcard'];
}
if (!empty($options['wildcard_substitution']) && !isset($options['exception']['title'])) {
// Enable the checkbox if the title is filled in.
$this->options['exception']['title_enable'] = 1;
$this->options['exception']['title'] = $options['wildcard_substitution'];
}
if (!isset($options['summary']['format']) && !empty($options['style_plugin'])) {
$this->options['summary']['format'] = $options['style_plugin'];
}
// Setup default value.
$options['style_options'] = isset($options['style_options']) ? $options['style_options'] : array();
if (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary asc') {
$this->options['default_action'] = 'summary';
$this->options['summary']['sort_order'] = 'asc';
$this->options['summary']['number_of_records'] = 0;
$this->options['summary_options'] = $options['style_options'];
}
elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary desc') {
$this->options['default_action'] = 'summary';
$this->options['summary']['sort_order'] = 'desc';
$this->options['summary']['number_of_records'] = 0;
$this->options['summary_options'] = $options['style_options'];
}
elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary asc by count') {
$this->options['default_action'] = 'summary';
$this->options['summary']['sort_order'] = 'asc';
$this->options['summary']['number_of_records'] = 1;
$this->options['summary_options'] = $options['style_options'];
}
elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary desc by count') {
$this->options['default_action'] = 'summary';
$this->options['summary']['sort_order'] = 'desc';
$this->options['summary']['number_of_records'] = 1;
$this->options['summary_options'] = $options['style_options'];
}
if (!empty($options['title']) && !isset($options['title_enable'])) {
$this->options['title_enable'] = 1;
}
if (!empty($options['breadcrumb']) && !isset($options['breadcrumb_enable'])) {
$this->options['breadcrumb_enable'] = 1;
}
if (!empty($options['validate_type']) && !isset($options['validate']['type'])) {
$this->options['validate']['type'] = $options['validate_type'];
$this->options['specify_validation'] = 1;
}
if (!empty($options['validate_fail']) && !isset($options['validate']['fail'])) {
$this->options['validate']['fail'] = $options['validate_fail'];
$this->options['specify_validation'] = 1;
}
}
/**
* Give an argument the opportunity to modify the breadcrumb, if it wants.
* This only gets called on displays where a breadcrumb is actually used.
......
......@@ -120,160 +120,6 @@ function init(&$view, &$display, $options = NULL) {
$this->unpack_options($this->options, $options);
}
// Translate changed settings:
$items_per_page = $this->get_option('items_per_page');
$offset = $this->get_option('offset');
$use_pager = $this->get_option('use_pager');
$pager = $this->get_option('pager');
// Check if the pager options were already converted.
// The pager settings of a Views 2.x view specifying 10 items with an
// offset of 0 and no pager is the same as of a Views 3.x view with
// default settings. In this case, the only way to determine which case we
// are dealing with is checking the API version but that's only available
// for exported Views as it's not stored in the database.
// If you would like to change this code, really take care that you thought
// of every possibility.
// @TODO: Provide a way to convert the database views as well.
if (((!empty($items_per_page) && $items_per_page != 10) || !empty($offset) || !empty($use_pager))
|| (!empty($view->api_version) && $view->api_version == 2)) {
// Find out the right pager type.
// If the view "use pager" it's a normal/full pager.
if ($use_pager) {
$type = 'full';
}
// If it does not use pager, but 0 items per page it should not page
// else it should display just a certain amount of items.
else {
$type = $items_per_page ? 'some' : 'none';
}
// Setup the pager options.
$pager = array(
'type' => $type,
'options' => array(
'offset' => intval($offset)
),
);
if ($items_per_page) {
$pager['options']['items_per_page'] = $items_per_page;
}
// Setup the pager element.
if ($id = $this->get_option('pager_element')) {
$pager['options']['id'] = $id;
}
// Unset the previous options
// After edit and save the view they will be erased
$this->set_option('items_per_page', NULL);
$this->set_option('offset', NULL);
$this->set_option('use_pager', NULL);
$this->set_option('pager', $pager);
$changed = TRUE;
}
// Plugable headers, footer and empty texts are
// not compatible with previous version of views
// This code converts old values into a configured handler for each area
foreach (array('header', 'footer', 'empty') as $area) {
$converted = FALSE;
if (isset($this->options[$area]) && !is_array($this->options[$area])) {
if (!empty($this->options[$area])) {
$content = $this->get_option($area);
if (!empty($content) && !is_array($content)) {
$format = $this->get_option($area . '_format');
$options = array(
'id' => 'area',
'table' => 'views',
'field' => 'area',
'label' => '',
'relationship' => 'none',
'group_type' => 'group',
'content' => $content,
'format' => !empty($format) ? $format : filter_default_format(),
);
if ($area != 'empty' && $empty = $this->get_option($area . '_empty')) {
$options['empty'] = $empty;
}
$this->set_option($area, array('text' => $options));
$converted = TRUE;
$changed = TRUE;
}
}
// Ensure that options are at least an empty array
if (!$converted) {
$this->set_option($area, array());
}
}
}
// Convert distinct setting from display to query settings.
$distinct = $this->get_option('distinct');
if (!empty($distinct)) {
$query_settings = $this->get_option('query');
$query_settings['options']['distinct'] = $distinct;
$this->set_option('query', $query_settings);
// Clear the values
$this->set_option('distinct', NULL);
$changed = TRUE;
}
// Convert field language settings.
$query_options = $this->get_option('query');
if (isset($query_options['options']['field_language'])) {
$this->set_option('field_language', $query_options['options']['field_language']);
unset($query_options['options']['field_language']);
$changed = TRUE;
}
if (isset($query_options['options']['field_language_add_to_query'])) {
$this->set_option('field_language_add_to_query', $query_options['options']['field_language_add_to_query']);
unset($query_options['options']['field_language_add_to_query']);
$changed = TRUE;
}
$this->set_option('query', $query_options);
// Convert filter groups.
$filter_groups = $this->get_option('filter_groups');
// Only convert if it wasn't converted yet, which is the case if there is a 0 group.
if (isset($filter_groups['groups'][0])) {
// Update filter groups.
$filter_groups ['groups'] = views_array_key_plus($filter_groups['groups']);
$this->set_option('filter_groups', $filter_groups);
// Update the filter group on each filter.
$filters = $this->get_option('filters');
foreach ($filters as &$filter) {
if (isset($filter['group'])) {
$filter['group']++;
}
else {
$filter['group'] = 1;
}
}
$this->set_option('filters', $filters);
$changed = TRUE;
}
// Filter groups were allowed to be rewritten without its filters, so
// before this update the view was using the default values. To be sure that
// the existing view isn't broken, don't use this overridden values but copy
// them from the default display. Only do this if the filters are overridden
// but the filter_groups are not marked as so.
if (!$this->is_default_display() && !$this->options['defaults']['filters'] && $this->options['defaults']['filter_groups']) {
// Set filter_groups to be overridden and save the value in the
// display_options as well.
$this->options['defaults']['filter_groups'] = FALSE;
$this->display->display_options['defaults']['filter_groups'] = $this->options['defaults']['filter_groups'];
// Copy the filter_groups from the default, and add them to the
// display_options as well. $this->default_display is not initialized at
// this point.
$this->options['filter_groups'] = $this->view->display['default']->handler->options['filter_groups'];
$this->display->display_options['filter_groups'] = $this->options['filter_groups'];
$changed = TRUE;
}
// Mark the view as changed so the user has a chance to save it.
if ($changed) {
$this->view->changed = TRUE;
......@@ -578,20 +424,6 @@ function option_definition() {
'default' => FALSE,
'bool' => TRUE,
),
// This is legacy code:
// Items_per/offset/use_pager is moved to the pager plugin
// but the automatic update path needs this items defined, so don't remove it.
// @see views_plugin_display::init()
'items_per_page' => array(
'default' => 10,
),
'offset' => array(
'default' => 0,
),
'use_pager' => array(
'default' => FALSE,
'bool' => TRUE,
),
'use_more' => array(
'default' => FALSE,
'bool' => TRUE,
......
......@@ -92,10 +92,6 @@ function allow_advanced_render() {
return TRUE;
}
function init(&$view, &$options) {
parent::init($view, $options);
}
/**
* Called to add the field to a query.
*/
......
......@@ -85,15 +85,9 @@ function init(&$view, &$options) {
$this->value = $this->options['value'];
$this->group_info = $this->options['group_info']['default_group'];
// Compatibility: The new UI changed several settings.
if (!empty($options['exposed']) && !empty($options['expose']['optional']) && !isset($options['expose']['required'])) {
$this->options['expose']['required'] = !$options['expose']['optional'];
}
if (!empty($options['exposed']) && !empty($options['expose']['single']) && !isset($options['expose']['multiple'])) {
$this->options['expose']['multiple'] = !$options['expose']['single'];
}
// Set the default value of the operator ID.
if (!empty($options['exposed']) && !empty($options['expose']['operator']) && !isset($options['expose']['operator_id'])) {
$this->options['expose']['operator_id'] = $options['expose']['operator_id'] = $options['expose']['operator'];
$this->options['expose']['operator_id'] = $options['expose']['operator'];
}
if ($this->multiple_exposed_input()) {
......@@ -101,6 +95,7 @@ function init(&$view, &$options) {
$this->options['expose']['multiple'] = TRUE;
}
// If there are relationships in the view, allow empty should be true
// so that we can do IS NULL checks on items. Not all filters respect
// allow empty, but string and numeric do and that covers enough.
......
......@@ -70,7 +70,7 @@ function view_test_argument_validate_php($string) {
$handler->display->display_options['arguments']['null']['field'] = 'null';
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['null']['validate_type'] = 'php';
$handler->display->display_options['arguments']['null']['validate']['type'] = 'php';
$handler->display->display_options['arguments']['null']['validate_options']['code'] = $code;
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
......@@ -102,7 +102,7 @@ function view_argument_validate_numeric() {
$handler->display->display_options['arguments']['null']['field'] = 'null';
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['null']['validate_type'] = 'numeric';
$handler->display->display_options['arguments']['null']['validate']['type'] = 'numeric';
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
return $view;
......
......@@ -145,6 +145,7 @@ protected function getGroupedExposedFilters() {
'table' => 'views_test',
'field' => 'name',
'relationship' => 'none',
'group' => 1,
'exposed' => TRUE,
'expose' => array(
'operator' => 'name_op',
......
......@@ -84,22 +84,6 @@ function viewFilterGroupsOverriding() {
return $view;
}
/**
* Based on a bug some filter_groups landed in the overridden display, even the filters weren't overridden.
* This caused multiple issues.
* Take sure that the value from the default display are used.
*
* @see http://drupal.org/node/1259608
* @see views_plugin_display::init()
*/
function testFilterGroupsUpdating() {
$view = $this->viewFilterGroupsUpdating();
$view->init_display();
$this->assertFalse($view->display['page']->handler->options['defaults']['filter_groups']);
$this->assertEqual($view->display['default']->handler->options['filter_groups'], $view->display['page']->handler->options['filter_groups'], 'Take sure the default options are used for the filter_groups');
}
/**
* Returns a test view for testFilterGroupUpdating.
*
......
......@@ -22,16 +22,6 @@
*/
class NodeNewComments extends Numeric {
function init(&$view, &$options) {
parent::init($view, $options);
// translate an older setting:
if (!empty($options['no_empty'])) {
$this->options['hide_empty'] = TRUE;
unset($this->options['no_empty']);
}
}
function construct() {
parent::construct();
$this->additional_fields['nid'] = 'nid';
......
......@@ -92,12 +92,6 @@ function init(&$view, &$options) {
$this->limit_values = TRUE;
}
}
// Convert old style entity id group column to new format.
// @todo Remove for next major version.
if ($this->options['group_column'] == 'entity id') {
$this->options['group_column'] = 'entity_id';
}
}
/**
......
......@@ -46,17 +46,6 @@ function option_definition() {
return $options;
}
/**
* Override init function to convert fulltext view-mode to full.
*/
function init(&$view, &$display, $options = NULL) {
parent::init($view, $display, $options);
if ($this->options['item_length'] == 'fulltext') {
$this->options['item_length'] = 'full';
}
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment