Commit 4fc76df7 authored by merlinofchaos's avatar merlinofchaos

UI saves! Simple view even works again!

parent eea55446
......@@ -342,4 +342,12 @@ html.js a.views-button-remove {
#arrange .form-item {
padding: 0;
}
\ No newline at end of file
}
div.views-basic-info div.view-changed {
float: right;
}
div.views-basic-info div.view-hide {
display: none;
}
......@@ -195,6 +195,23 @@ function views_ui_edit_view_form(&$form_state, $view) {
return $form;
}
/**
* Submit handler for the edit view form.
*/
function views_ui_edit_view_form_submit($form, &$form_state) {
$form_state['view']->save();
drupal_set_message(t('The view has been saved.'));
// Make sure menu items get rebuilt as neces
menu_rebuild();
// Clear the views cache.
cache_clear_all('*', 'cache_views');
// Clear the page cache.
cache_clear_all();
}
/**
* Display the edit view form.
*
......@@ -205,28 +222,33 @@ function theme_views_ui_edit_view($view) {
$output = '';
$save_button = drupal_get_form('views_ui_edit_view_form', $view);
$table = views_fetch_data($view->base_table);
$base_table = !empty($table['table']['base']['title']) ?
$table['table']['base']['title'] : t('Unknown or missing table name');
$output .= '<div class="views-basic-info">';
if (!empty($view->changed)) {
if (!is_numeric($view->vid)) {
$warning = t('This view has not yet been created and will not be entered into the database until you click <b>Save</b>, below.');
$output .= '<div class="view-changed view-new">' . t('New view') . '</div>';
}
else {
$warning = t('This view has been modified and changes will not saved to the database until you click <b>Save</b>, below.');
$output .= '<div class="view-changed">' . t('Changed view') . '</div>';
}
$output .= '<div class="warning">' . $warning . "</div>\n";
}
$table = views_fetch_data($view->base_table);
$base_table = !empty($table['table']['base']['title']) ?
$table['table']['base']['title'] : t('Unknown or missing table name');
$output .= '<div class="views-basic-info">';
else {
$output .= '<div class="view-changed view-hide">' . t('Changed view') . '</div>';
}
$output .= t('View %name, displaying items of type <b>@base</b>.',
array('%name' => $view->name, '@base' => $base_table));
$output .= '</div>';
views_include('tabs');
$tabs = new views_tabset;
$view->init_display('default');
if (!$view->set_display('default')) {
views_ajax_render(t('Invalid display id'));
}
foreach ($view->display as $display) {
list($title, $body) = views_ui_display_tab($view, $display);
// The first display is the default.
......@@ -385,7 +407,9 @@ function views_ui_regenerate_tabs($view, $display_id = NULL, $object = NULL) {
$displays = $display_id;
}
$view->init_display();
if (!$view->set_display('default')) {
views_ajax_render(t('Invalid display id'));
}
if (!is_object($object)) {
$object = new stdClass();
......@@ -448,7 +472,10 @@ function views_ui_add_display($js, $view) {
$view = $form_state['view'];
$id = $form_state['id'];
$view->init_display();
if (!$view->set_display('default')) {
views_ajax_render(t('Invalid display id'));
}
list($title, $body) = views_ui_display_tab($view, $view->display[$id]);
$output = new stdClass;
......@@ -652,7 +679,9 @@ function views_ui_edit_display($js, $view, $display_id, $section) {
* Form constructor callback to edit display of a view
*/
function views_ui_edit_display_form(&$form_state, $view, $display_id, $section) {
$view->init_display($display_id);
if (!$view->set_display($display_id)) {
views_ajax_render(t('Invalid display id'));
}
$display = &$view->display[$display_id];
$form_state['view'] = $view;
......@@ -726,7 +755,9 @@ function views_ui_rearrange_form(&$form_state, $view, $display_id, $type) {
$types = views_object_types();
$form['#title'] = t('Rearrange @type', array('@type' => $types[$type]['title']));
$types = views_object_types();
$view->init_display($display_id);
if (!$view->set_display($display_id)) {
views_ajax_render(t('Invalid display id'));
}
$display = &$view->display[$display_id];
if ($display->handler->defaultable_sections($types[$type]['plural'])) {
......@@ -868,7 +899,9 @@ function views_ui_add_item($js, $view, $display_id, $type) {
* Form to add_item items in the views UI.
*/
function views_ui_add_item_form(&$form_state, $view, $display_id, $type) {
$view->init_display($display_id);
if (!$view->set_display($display_id)) {
views_ajax_render(t('Invalid display id'));
}
$display = &$view->display[$display_id];
$types = views_object_types();
......@@ -942,13 +975,15 @@ function views_ui_config_item($js, $view, $display_id, $type, $id) {
*/
function views_ui_config_item_form(&$form_state, $view, $display_id, $type, $id) {
$form = array('options' => array('#tree' => TRUE));
$view->init_display($display_id);
if (!$view->set_display($display_id)) {
views_ajax_render(t('Invalid display id'));
}
$item = $view->get_item($display_id, $type, $id);
if ($item) {
$handler = views_get_handler($item->table, $item->field, $type);
if (empty($handler)) {
$form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item->tablename, '@field' => $item->field)));
$form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item->table, '@field' => $item->field)));
break;
}
$handler->init($view, $item);
......@@ -1017,13 +1052,15 @@ function views_ui_change_style($js, $view, $display_id, $type, $id) {
*/
function views_ui_change_style_form(&$form_state, $view, $display_id, $type, $id) {
$form = array('options' => array('#tree' => TRUE));
$view->init_display($display_id);
if (!$view->set_display($display_id)) {
views_ajax_render(t('Invalid display id'));
}
$item = $view->get_item($display_id, $type, $id);
if ($item) {
$handler = views_get_handler($item->table, $item->field, $type);
if (empty($handler)) {
$form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item->tablename, '@field' => $item->field)));
$form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item->table, '@field' => $item->field)));
break;
}
$handler->init($view, $item);
......@@ -1087,13 +1124,15 @@ function views_ui_config_style($js, $view, $display_id, $type, $id) {
*/
function views_ui_config_style_form(&$form_state, $view, $display_id, $type, $id) {
$form = array('options' => array('#tree' => TRUE));
$view->init_display($display_id);
if (!$view->set_display($display_id)) {
views_ajax_render(t('Invalid display id'));
}
$item = $view->get_item($display_id, $type, $id);
if ($item) {
$handler = views_get_handler($item->table, $item->field, $type);
if (empty($handler)) {
$form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item->tablename, '@field' => $item->field)));
$form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item->table, '@field' => $item->field)));
break;
}
$handler->init($view, $item);
......@@ -1105,9 +1144,7 @@ function views_ui_config_style_form(&$form_state, $view, $display_id, $type, $id
$form['style_options'] = array(
'#tree' => TRUE,
);
$plugin->init($view, $view->display[$display_id]);
// Override the options since it thinks it's getting them from the display.
$plugin->options = $item->style_options;
$plugin->init($view, $view->display[$display_id], $item->style_options);
$plugin->options_form($form['style_options'], $form_state);
}
......@@ -1159,7 +1196,7 @@ function views_ui_add_info($type, $view, $display) {
foreach ($display->handler->get_option($types[$type]['plural']) as $field) {
$handler = views_get_handler($field->table, $field->field, $type);
if (empty($handler)) {
$output .= t("Error: handler for @table > @field doesn't exist!", array('@table' => $field->tablename, '@field' => $field->field)) . '<br/>';
$output .= t("Error: handler for @table > @field doesn't exist!", array('@table' => $field->table, '@field' => $field->field)) . '<br/>';
continue;
}
$handler->init($view, $field);
......
......@@ -152,8 +152,8 @@ class views_handler extends views_object {
$this->data = &$data;
// This exist on most handlers, but not all. So they are still optional.
if (isset($data->tablename)) {
$this->table = $data->tablename;
if (isset($data->table)) {
$this->table = $data->table;
}
if (isset($data->field)) {
......
......@@ -709,7 +709,7 @@ class views_display_plugin extends views_object {
function render_textarea($area) {
$format_string = $area . '_format';
return check_markup($this->display->$area, $this->display->$format_string);
return check_markup($this->get_option($area), $this->get_option($format_string));
}
/**
......@@ -843,7 +843,7 @@ class views_display_plugin_page extends views_display_plugin {
// Identify URL embedded arguments and correlate them to a handler
'load arguments' => array($this->view->name, '%index'),
// Basic menu title
'title' => $this->display->title,
'title' => $this->display->handler->get_option('title'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
......@@ -1075,18 +1075,26 @@ class views_display_plugin_block extends views_display_plugin {
*/
class views_style_plugin extends views_object {
/**
* This is set both here and in the plugin settings because
* the object may not have access to the plugin settings.
* Initialize a style plugin.
*
* @param $view
* @param $display
* @param $options
* The style options might come externally as the style can be sourced
* from at least two locations. If it's not included, look on the display.
*/
var $uses_row_plugin = FALSE;
function init(&$view, &$display) {
function init(&$view, &$display, $options = NULL) {
$this->view = $view;
$this->display = $display;
$this->options = $display->handler->get_option('style_options');
if (isset($options)) {
$this->options = $options;
}
else {
$this->options = $display->handler->get_option('style_options');
}
if ($this->uses_row_plugin) {
$this->row_plugin = views_get_plugin('row', $display->get_options('row_plugin'));
if ($this->uses_row_plugin()) {
$this->row_plugin = views_get_plugin('row', $display->handler->get_option('row_plugin'));
// initialize the row plugin.
if ($this->row_plugin) {
$this->row_plugin->init($view, $display);
......@@ -1094,10 +1102,14 @@ class views_style_plugin extends views_object {
}
}
function uses_row_plugin() {
return !empty($this->definition['uses row plugin']);
}
/**
* Static member function to set default options.
*/
function construct($display) {
function options(&$display) {
return array();
}
......@@ -1130,7 +1142,7 @@ class views_style_plugin_default extends views_style_plugin {
*/
function render() {
if (empty($this->row_plugin)) {
// @todo: Log some form of error here?
vpr('views_style_plugin_default: Missing row plugin');
return;
}
// @todo: This needs to be able to support either a database resource OR
......@@ -1273,7 +1285,7 @@ class views_row_plugin extends views_object {
function init(&$view, &$display) {
$this->view = $view;
$this->display = $display;
$this->options = $display->get_options('row_options');
$this->options = $display->handler->get_option('row_options');
}
/**
......
This diff is collapsed.
......@@ -244,7 +244,7 @@ class views_handler_field_node extends views_handler_field {
function render_link($data, $values) {
if (!empty($this->data->link_to_node)) {
return l($data, "node/" . $values->{$this->node_field}, array('html' => TRUE));
return l($data, "node/" . $values->{$this->nid_field}, array('html' => TRUE));
}
else {
return $data;
......
......@@ -37,7 +37,7 @@ function template_preprocess_views_view_row(&$vars) {
$view = $vars['view'];
// Loop through the fields for this view.
foreach ($view->get_fields($view->current_display) as $field) {
foreach ($view->field as $field) {
if (!empty($field->handler) && is_object($field->handler)) {
$themes = array(
'views_view_field__' . $view->name . '__' . $field->handler->field_alias,
......
......@@ -118,291 +118,6 @@ function views_schema() {
'indexes' => array('vid' => array('vid', 'position')),
);
$schema['views_argument'] = array(
'description' => t('Stores information about each argument attached to a view.'),
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The view this display is attached to.'),
'no export' => TRUE,
),
'position' => array(
'type' => 'int',
'default' => 0,
'description' => t('The order in which this information is loaded.'),
),
'tablename' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The name of the table this field is attached to.'),
),
'field' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The name of the field.'),
),
'relationship' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The relationship this field belongs to.'),
),
'type' => array(
'type' => 'varchar',
'length' => '64',
'default' => '',
'not null' => TRUE,
'description' => t('The type of the display. Usually page, block or embed, but is pluggable so may be other things.'),
),
'style' => array(
'type' => 'varchar',
'length' => '64',
'default' => '',
'not null' => TRUE,
'description' => t('The type of the display. Usually page, block or embed, but is pluggable so may be other things.'),
),
'default_action' => array(
'type' => 'varchar',
'length' => '32',
'default' => '',
'not null' => TRUE,
'description' => t('What to do if this argument is not present.'),
),
'title' => array(
'type' => 'varchar',
'length' => '255',
'default' => '',
'not null' => TRUE,
'description' => t('The title to use if this argument is present.'),
),
'wildcard' => array(
'type' => 'varchar',
'length' => '32',
'default' => '*',
'description' => t('What to use for a wildcard in the URL for this argument.'),
),
'wildcard_text' => array(
'type' => 'varchar',
'length' => '64',
'default' => t('All'),
'description' => t('The textual representation of the argument, for use in titles. For example, if the argument is *, the text represnation might be "all".'),
),
'options' => array(
'type' => 'blob',
'description' => t('A serialized array of options for this field.'),
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
),
'indexes' => array('vid' => array('vid', 'position')),
);
$schema['views_field'] = array(
'description' => t('Stores information about each field attached to a view.'),
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The view this display is attached to.'),
'no export' => TRUE,
),
'position' => array(
'type' => 'int',
'default' => 0,
'description' => t('The order in which this information is loaded.'),
),
'display_id' => array(
'type' => 'int',
'default' => 0,
'description' => t('The display for which these fields are valid.'),
),
'tablename' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The name of the table this field is attached to.'),
),
'field' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The name of the field.'),
),
'relationship' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The relationship this field belongs to.'),
),
'options' => array(
'type' => 'blob',
'description' => t('A serialized array of options for this field.'),
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
),
'indexes' => array('vid' => array('vid', 'position')),
);
$schema['views_sort'] = array(
'description' => t('Stores information about each sort criterion attached to a view.'),
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The view this display is attached to.'),
'no export' => TRUE,
),
'position' => array(
'type' => 'int',
'default' => 0,
'description' => t('The order in which this information is loaded.'),
),
'tablename' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The name of the table this field is attached to.'),
),
'field' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The name of the field.'),
),
'relationship' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The relationship this field belongs to.'),
),
'order' => array(
'type' => 'varchar',
'length' => '4',
'description' => t('Either ASC or DESC.'),
),
'options' => array(
'type' => 'blob',
'description' => t('A serialized array of options for this field.'),
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
'exposed' => array(
'type' => 'int',
'default' => 0,
'size' => 'tiny',
'description' => t('True if this sort is exposed in the UI.'),
),
'exposed_options' => array(
'type' => 'blob',
'description' => t('A serialized array of options for exposed sorts.'),
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
),
'indexes' => array('vid' => array('vid', 'position')),
);
$schema['views_filter'] = array(
'description' => t('Stores information about each filter attached to a view.'),
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The view this display is attached to.'),
'no export' => TRUE,
),
'position' => array(
'type' => 'int',
'default' => 0,
'description' => t('The order in which this information is loaded.'),
),
'group' => array(
'type' => 'int',
'default' => 0,
'description' => t('Which filter group this filter belongs to, so that AND and OR can be separated properly.'),
),
'tablename' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The name of the table this field is attached to.'),
),
'field' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The name of the field.'),
),
'relationship' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The relationship this field belongs to.'),
),
'operator' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The operator for this filter. For example, == or > or <.'),
),
'value' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The value being tested for this filter.'),
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
'options' => array(
'type' => 'blob',
'description' => t('A serialized array of options for this field.'),
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
'exposed' => array(
'type' => 'int',
'default' => 0,
'size' => 'tiny',
'description' => t('True if this filter is exposed in the UI.'),
),
'exposed_options' => array(
'type' => 'blob',
'description' => t('A serialized array of options for exposed filters.'),
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
),
'indexes' => array('vid' => array('vid', 'position')),
);
$schema['views_relationship'] = array(
'description' => t('Stores information about each filter attached to a view.'),
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The view this display is attached to.'),
'no export' => TRUE,
),
'position' => array(
'type' => 'int',
'default' => 0,
'description' => t('The order in which this information is loaded.'),
),
'relationship' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The actual relationship used.'),
),
'link' => array(
'type' => 'varchar',
'length' => '255',
'description' => t('The relationship this links back to.'),
),
),
'indexes' => array('vid' => array('vid', 'position')),
);
// This is unfortunately cut & pasted from system.module since cache has no way of
// telling us what the proper schema is.
$schema['cache_views'] = array(
......
......@@ -178,7 +178,7 @@ function views_access($view, $account = NULL) {
if (!$view) {
return FALSE;
}
if (!$view->init_display($display_id)) {
if (!$view->set_display($display_id)) {
return FALSE;
}
}
......@@ -614,7 +614,7 @@ function views_get_applicable_views($type) {
// This view uses hook menu. Clone it so that different handlers
// don't trip over each other, and add it to the list.
$v = drupal_clone($view);
if ($v->init_display($display->id)) {
if ($v->set_display($display->id)) {
$result[] = array($v, $display->id);
}
}
......
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