00001 <?php
00002
00003 interface ViewsWizardInterface {
00004 function __construct($plugin);
00005
00009 function build_form($form, &$form_state);
00010
00016 function validate($form, &$form_state);
00017
00025 function create_view($form, &$form_state);
00026 }
00027
00031 class ViewsWizardException extends Exception {
00032 }
00033
00037 class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
00038 protected $base_table;
00039 protected $entity_type;
00040 protected $entity_info = array();
00041 protected $validated_views = array();
00042 protected $plugin = array();
00043 protected $filter_defaults = array(
00044 'id' => NULL,
00045 'expose' => array('operator' => FALSE),
00046 'group' => 1,
00047 );
00048
00049 function __construct($plugin) {
00050 $this->base_table = $plugin['base_table'];
00051 $default = $this->filter_defaults;
00052
00053 if (isset($plugin['filters'])) {
00054 foreach ($plugin['filters'] as $name => $info) {
00055 $default['id'] = $name;
00056 $plugin['filters'][$name] = $info + $default;
00057 }
00058 }
00059
00060 $this->plugin = $plugin;
00061
00062 $entities = entity_get_info();
00063 foreach ($entities as $entity_type => $entity_info) {
00064 if (isset($entity_info['base table']) && $this->base_table == $entity_info['base table']) {
00065 $this->entity_info = $entity_info;
00066 $this->entity_type = $entity_type;
00067 }
00068 }
00069 }
00070
00071 function build_form($form, &$form_state) {
00072 $style_options = views_fetch_plugin_names('style', 'normal', array($this->base_table));
00073 $feed_row_options = views_fetch_plugin_names('row', 'feed', array($this->base_table));
00074 $path_prefix = url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=');
00075
00076
00077 $this->build_filters($form, $form_state);
00078 $this->build_sorts($form, $form_state);
00079
00080 $form['displays']['page'] = array(
00081 '#type' => 'fieldset',
00082 '#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),),
00083 '#tree' => TRUE,
00084 );
00085 $form['displays']['page']['create'] = array(
00086 '#title' => t('Create a page'),
00087 '#type' => 'checkbox',
00088 '#attributes' => array('class' => array('strong')),
00089 '#default_value' => TRUE,
00090 '#id' => 'edit-page-create',
00091 );
00092
00093
00094
00095 $form['displays']['page']['options'] = array(
00096 '#type' => 'container',
00097 '#attributes' => array('class' => array('options-set'),),
00098 '#dependency' => array(
00099 'edit-page-create' => array(1),
00100 ),
00101 '#pre_render' => array('ctools_dependent_pre_render'),
00102 '#prefix' => '<div><div id="edit-page-wrapper">',
00103 '#suffix' => '</div></div>',
00104 '#parents' => array('page'),
00105 );
00106
00107 $form['displays']['page']['options']['title'] = array(
00108 '#title' => t('Page title'),
00109 '#type' => 'textfield',
00110 );
00111 $form['displays']['page']['options']['path'] = array(
00112 '#title' => t('Path'),
00113 '#type' => 'textfield',
00114 '#field_prefix' => $path_prefix,
00115 );
00116 $form['displays']['page']['options']['style'] = array(
00117 '#type' => 'fieldset',
00118 '#attributes' => array('class' => array('container-inline', 'fieldset-no-legend')),
00119 );
00120
00121
00122 $form['displays']['page']['options']['style']['style_plugin'] = array(
00123 '#title' => t('Display format'),
00124 '#help_topic' => 'style',
00125 '#type' => 'select',
00126 '#options' => $style_options,
00127 );
00128 $style_form = &$form['displays']['page']['options']['style'];
00129 $style_form['style_plugin']['#default_value'] = views_ui_get_selected($form_state, array('page', 'style', 'style_plugin'), 'default', $style_form['style_plugin']);
00130
00131
00132 views_ui_add_ajax_trigger($style_form, 'style_plugin', array('displays', 'page', 'options'));
00133
00134 $this->build_form_style($form, $form_state, 'page');
00135 $form['displays']['page']['options']['items_per_page'] = array(
00136 '#title' => t('Items to display'),
00137 '#type' => 'textfield',
00138 '#default_value' => '10',
00139 '#size' => 5,
00140 '#element_validate' => array('views_element_validate_integer'),
00141 );
00142 $form['displays']['page']['options']['pager'] = array(
00143 '#title' => t('Use a pager'),
00144 '#type' => 'checkbox',
00145 '#default_value' => TRUE,
00146 );
00147 $form['displays']['page']['options']['link'] = array(
00148 '#title' => t('Create a menu link'),
00149 '#type' => 'checkbox',
00150 '#id' => 'edit-page-link',
00151 );
00152 $form['displays']['page']['options']['link_properties'] = array(
00153 '#type' => 'container',
00154 '#dependency' => array(
00155 'edit-page-link' => array(1),
00156 ),
00157 '#pre_render' => array('ctools_dependent_pre_render'),
00158 '#prefix' => '<div id="edit-page-link-properties-wrapper">',
00159 '#suffix' => '</div>',
00160 );
00161 if (module_exists('menu')) {
00162 $menu_options = menu_get_menus();
00163 }
00164 else {
00165
00166 $menu_options = menu_list_system_menus();
00167 foreach ($menu_options as $name => $title) {
00168 $menu_options[$name] = t($title);
00169 }
00170 }
00171 $form['displays']['page']['options']['link_properties']['menu_name'] = array(
00172 '#title' => t('Menu'),
00173 '#type' => 'select',
00174 '#options' => $menu_options,
00175 );
00176 $form['displays']['page']['options']['link_properties']['title'] = array(
00177 '#title' => t('Link text'),
00178 '#type' => 'textfield',
00179 );
00180
00181 if ($feed_row_options) {
00182 $form['displays']['page']['options']['feed'] = array(
00183 '#title' => t('Include an RSS feed'),
00184 '#type' => 'checkbox',
00185 '#id' => 'edit-page-feed',
00186 );
00187 $form['displays']['page']['options']['feed_properties'] = array(
00188 '#type' => 'container',
00189 '#dependency' => array(
00190 'edit-page-feed' => array(1),
00191 ),
00192 '#pre_render' => array('ctools_dependent_pre_render'),
00193 '#prefix' => '<div id="edit-page-feed-properties-wrapper">',
00194 '#suffix' => '</div>',
00195 );
00196 $form['displays']['page']['options']['feed_properties']['path'] = array(
00197 '#title' => t('Feed path'),
00198 '#type' => 'textfield',
00199 '#field_prefix' => $path_prefix,
00200 );
00201
00202 $form['displays']['page']['options']['feed_properties']['row_plugin'] = array(
00203 '#title' => t('Feed row style'),
00204 '#type' => 'select',
00205 '#options' => $feed_row_options,
00206 '#default_value' => key($feed_row_options),
00207 '#access' => (count($feed_row_options) > 1),
00208 '#dependency' => array(
00209 'edit-page-feed' => array(1),
00210 ),
00211 '#pre_render' => array('ctools_dependent_pre_render'),
00212 '#prefix' => '<div id="edit-page-feed-properties-row-plugin-wrapper">',
00213 '#suffix' => '</div>',
00214 );
00215 }
00216
00217 $form['displays']['block'] = array(
00218 '#type' => 'fieldset',
00219 '#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),),
00220 '#tree' => TRUE,
00221 );
00222 $form['displays']['block']['create'] = array(
00223 '#title' => t('Create a block'),
00224 '#type' => 'checkbox',
00225 '#attributes' => array('class' => array('strong')),
00226 '#id' => 'edit-block-create',
00227 );
00228
00229
00230
00231 $form['displays']['block']['options'] = array(
00232 '#type' => 'container',
00233 '#attributes' => array('class' => array('options-set'),),
00234 '#dependency' => array(
00235 'edit-block-create' => array(1),
00236 ),
00237 '#pre_render' => array('ctools_dependent_pre_render'),
00238 '#prefix' => '<div id="edit-block-wrapper">',
00239 '#suffix' => '</div>',
00240 '#parents' => array('block'),
00241 );
00242
00243 $form['displays']['block']['options']['title'] = array(
00244 '#title' => t('Block title'),
00245 '#type' => 'textfield',
00246 );
00247 $form['displays']['block']['options']['style'] = array(
00248 '#type' => 'fieldset',
00249 '#attributes' => array('class' => array('container-inline', 'fieldset-no-legend')),
00250 );
00251
00252
00253 $form['displays']['block']['options']['style']['style_plugin'] = array(
00254 '#title' => t('Display format'),
00255 '#help_topic' => 'style',
00256 '#type' => 'select',
00257 '#options' => $style_options,
00258 );
00259 $style_form = &$form['displays']['block']['options']['style'];
00260 $style_form['style_plugin']['#default_value'] = views_ui_get_selected($form_state, array('block', 'style', 'style_plugin'), 'default', $style_form['style_plugin']);
00261
00262
00263 views_ui_add_ajax_trigger($style_form, 'style_plugin', array('displays', 'block', 'options'));
00264
00265 $this->build_form_style($form, $form_state, 'block');
00266 $form['displays']['block']['options']['items_per_page'] = array(
00267 '#title' => t('Items per page'),
00268 '#type' => 'textfield',
00269 '#default_value' => '5',
00270 '#size' => 5,
00271 '#element_validate' => array('views_element_validate_integer'),
00272 );
00273 $form['displays']['block']['options']['pager'] = array(
00274 '#title' => t('Use a pager'),
00275 '#type' => 'checkbox',
00276 '#default_value' => FALSE,
00277 );
00278
00279 return $form;
00280 }
00281
00285 protected function build_form_style(&$form, &$form_state, $type) {
00286 $style_form =& $form['displays'][$type]['options']['style'];
00287 $style = $style_form['style_plugin']['#default_value'];
00288 $style_plugin = views_get_plugin('style', $style);
00289 if (isset($style_plugin) && $style_plugin->uses_row_plugin()) {
00290 $options = $this->row_style_options($type);
00291 $style_form['row_plugin'] = array(
00292 '#type' => 'select',
00293 '#title' => t('of'),
00294 '#options' => $options,
00295 '#access' => count($options) > 1,
00296 );
00297
00298
00299 $block_with_linked_titles_available = ($type == 'block' && isset($options['titles_linked']));
00300 $default_value = $block_with_linked_titles_available ? 'titles_linked' : key($options);
00301 $style_form['row_plugin']['#default_value'] = views_ui_get_selected($form_state, array($type, 'style', 'row_plugin'), $default_value, $style_form['row_plugin']);
00302
00303 views_ui_add_ajax_trigger($style_form, 'row_plugin', array('displays', $type, 'options', 'style', 'row_options'));
00304
00305
00306
00307 $style_form['row_options'] = array(
00308 '#theme_wrappers' => array('container'),
00309 );
00310 }
00311 elseif ($style_plugin->uses_fields()) {
00312 $style_form['row_plugin'] = array('#markup' => '<span>' . t('of fields') . '</span>');
00313 }
00314 }
00315
00321 protected function row_style_options($type) {
00322 $data = views_fetch_data($this->base_table);
00323
00324 $options = views_fetch_plugin_names('row', 'normal', array($this->base_table));
00325 return $options;
00326 }
00327
00334 protected function build_filters(&$form, &$form_state) {
00335
00336 $fields = views_fetch_fields($this->base_table, 'filter');
00337
00338 $entity_info = $this->entity_info;
00339
00340 if (isset($entity_info['bundle keys']) && isset($entity_info['bundles'])) {
00341
00342 $options = array('all' => t('All'));
00343 foreach ($entity_info['bundles'] as $type => $bundle) {
00344 $options[$type] = $bundle['label'];
00345 }
00346 $form['displays']['show']['type'] = array(
00347 '#type' => 'select',
00348 '#title' => t('of type'),
00349 '#options' => $options,
00350 );
00351 $selected_bundle = views_ui_get_selected($form_state, array('show', 'type'), 'all', $form['displays']['show']['type']);
00352 $form['displays']['show']['type']['#default_value'] = $selected_bundle;
00353
00354
00355
00356 views_ui_add_ajax_trigger($form['displays']['show'], 'type', array('displays'));
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 if (isset($fields['taxonomy_index.tid'])) {
00374
00375 if (!empty($entity_info['fieldable'])) {
00376
00377
00378
00379
00380 $bundles = array_keys($entity_info['bundles']);
00381
00382
00383 if (isset($selected_bundle) && in_array($selected_bundle, $bundles)) {
00384 $bundles = array($selected_bundle);
00385 }
00386 $tag_fields = array();
00387 foreach ($bundles as $bundle) {
00388 foreach (field_info_instances($this->entity_type, $bundle) as $instance) {
00389
00390
00391 if ($instance['widget']['type'] == 'taxonomy_autocomplete') {
00392 $tag_fields[] = $instance['field_name'];
00393 }
00394 }
00395 }
00396 $tag_fields = array_unique($tag_fields);
00397 if (!empty($tag_fields)) {
00398
00399
00400
00401
00402
00403
00404 if (in_array('field_tags', $tag_fields)) {
00405 $tag_field_name = 'field_tags';
00406 }
00407 else {
00408 $tag_field_name = reset($tag_fields);
00409 }
00410
00411 $form['displays']['show']['tagged_with'] = array(
00412 '#type' => 'textfield',
00413 '#title' => t('tagged with'),
00414 '#autocomplete_path' => 'taxonomy/autocomplete/' . $tag_field_name,
00415 '#size' => 30,
00416 '#maxlength' => 1024,
00417 '#field_name' => $tag_field_name,
00418 '#element_validate' => array('views_ui_taxonomy_autocomplete_validate'),
00419 );
00420 }
00421 }
00422 }
00423 }
00424
00430 protected function build_sorts(&$form, &$form_state) {
00431 $sorts = array(
00432 'none' => t('Unsorted'),
00433 );
00434
00435 if (!empty($this->plugin['created_column'])) {
00436 $sorts += array(
00437 $this->plugin['created_column'] . ':DESC' => t('Newest first'),
00438 $this->plugin['created_column'] . ':ASC' => t('Oldest first'),
00439 );
00440 }
00441 if (isset($this->plugin['available_sorts'])) {
00442 $sorts += $this->plugin['available_sorts'];
00443 }
00444
00445
00446 if (!empty($sorts)) {
00447 $form['displays']['show']['sort'] = array(
00448 '#type' => 'select',
00449 '#title' => t('sorted by'),
00450 '#options' => $sorts,
00451 '#default_value' => isset($this->plugin['created_column']) ? $this->plugin['created_column'] . ':DESC' : 'none',
00452 );
00453 }
00454 }
00455
00456 protected function instantiate_view($form, &$form_state) {
00457
00458 $view = views_new_view();
00459 $view->name = $form_state['values']['name'];
00460 $view->human_name = $form_state['values']['human_name'];
00461 $view->description = $form_state['values']['description'];
00462 $view->tag = 'default';
00463 $view->core = VERSION;
00464 $view->base_table = $this->base_table;
00465
00466
00467 $display_options = $this->build_display_options($form, $form_state);
00468
00469
00470
00471
00472 $this->alter_display_options($display_options, $form, $form_state);
00473
00474 $this->add_displays($view, $display_options, $form, $form_state);
00475
00476 return $view;
00477 }
00478
00486 protected function build_display_options($form, $form_state) {
00487
00488 $display_options['default'] = $this->default_display_options($form, $form_state);
00489 $display_options['default'] += array(
00490 'filters' => array(),
00491 'sorts' => array(),
00492 );
00493 $display_options['default']['filters'] += $this->default_display_filters($form, $form_state);
00494 $display_options['default']['sorts'] += $this->default_display_sorts($form, $form_state);
00495
00496
00497 if (!empty($form_state['values']['page']['create'])) {
00498 $display_options['page'] = $this->page_display_options($form, $form_state);
00499
00500
00501 if (!empty($form_state['values']['page']['feed'])) {
00502 $display_options['feed'] = $this->page_feed_display_options($form, $form_state);
00503 }
00504 }
00505
00506
00507 if (!empty($form_state['values']['block']['create'])) {
00508 $display_options['block'] = $this->block_display_options($form, $form_state);
00509 }
00510
00511 return $display_options;
00512 }
00513
00517 protected function alter_display_options(&$display_options, $form, $form_state) {
00518
00519
00520
00521 if (isset($this->plugin['path_field'])) {
00522 $path_field = $this->plugin['path_field'];
00523 $path_fields_added = FALSE;
00524 foreach ($display_options as $display_type => $options) {
00525 if (!empty($options['style_plugin']) && $options['style_plugin'] == 'jump_menu') {
00526
00527
00528 if (!$path_fields_added) {
00529
00530
00531
00532
00533 $path_fields = !empty($this->plugin['path_fields_supplemental']) ? $this->plugin['path_fields_supplemental'] : array();
00534 $path_fields[] = &$path_field;
00535
00536
00537
00538 foreach ($path_fields as &$field) {
00539 $field['id'] = view::generate_item_id($field['id'], $display_options['default']['fields']);
00540 $display_options['default']['fields'][$field['id']] = $field;
00541 }
00542
00543 $path_fields_added = TRUE;
00544 }
00545
00546
00547
00548 $display_options[$display_type]['style_options']['path'] = $path_field['id'];
00549 }
00550 }
00551 }
00552 }
00553
00557 protected function add_displays($view, $display_options, $form, $form_state) {
00558
00559 $default_display = $view->new_display('default', 'Master', 'default');
00560 foreach ($display_options['default'] as $option => $value) {
00561 $default_display->set_option($option, $value);
00562 }
00563
00564
00565 if (isset($display_options['page'])) {
00566 $display = $view->new_display('page', 'Page', 'page');
00567
00568
00569
00570 $this->set_default_options($display_options['page'], $display, $default_display);
00571
00572
00573 if (isset($display_options['feed'])) {
00574 $display = $view->new_display('feed', 'Feed', 'feed');
00575 $this->set_override_options($display_options['feed'], $display, $default_display);
00576 }
00577 }
00578
00579
00580 if (isset($display_options['block'])) {
00581 $display = $view->new_display('block', 'Block', 'block');
00582
00583
00584 if (!isset($display_options['page'])) {
00585 $this->set_default_options($display_options['block'], $display, $default_display);
00586 }
00587 else {
00588 $this->set_override_options($display_options['block'], $display, $default_display);
00589 }
00590 }
00591 }
00592
00597 protected function default_display_options($form, $form_state) {
00598 $display_options = array();
00599 $display_options['access']['type'] = 'none';
00600 $display_options['cache']['type'] = 'none';
00601 $display_options['query']['type'] = 'views_query';
00602 $display_options['exposed_form']['type'] = 'basic';
00603 $display_options['pager']['type'] = 'full';
00604 $display_options['style_plugin'] = 'default';
00605 $display_options['row_plugin'] = 'fields';
00606
00607
00608
00609
00610 $data = views_fetch_data($this->base_table);
00611 if (isset($data['table']['base']['defaults']['field'])) {
00612 $field = $data['table']['base']['defaults']['field'];
00613 }
00614 else {
00615 foreach ($data as $field => $field_data) {
00616 if (isset($field_data['field']['handler'])) {
00617 break;
00618 }
00619 }
00620 }
00621 $display_options['fields'][$field] = array(
00622 'table' => $this->base_table,
00623 'field' => $field,
00624 'id' => $field,
00625 );
00626
00627 return $display_options;
00628 }
00629
00630 protected function default_display_filters($form, $form_state) {
00631 $filters = array();
00632
00633
00634 if (isset($this->plugin['filters'])) {
00635 foreach ($this->plugin['filters'] as $name => $info) {
00636 $filters[$name] = $info;
00637 }
00638 }
00639
00640
00641 $filters = array_merge($filters, $this->default_display_filters_user($form, $form_state));
00642
00643 return $filters;
00644 }
00645
00646 protected function default_display_filters_user($form, $form_state) {
00647 $filters = array();
00648
00649 if (!empty($form_state['values']['show']['type']) && $form_state['values']['show']['type'] != 'all') {
00650 $bundle_key = $this->entity_info['bundle keys']['bundle'];
00651
00652
00653
00654 $fields = views_fetch_fields($this->base_table, 'filter');
00655 if (isset($fields[$this->base_table . '.' . $bundle_key])) {
00656 $table = $this->base_table;
00657 }
00658 else {
00659 foreach ($fields as $field_name => $value) {
00660 if ($pos = strpos($field_name, '.' . $bundle_key)) {
00661 $table = substr($field_name, 0, $pos);
00662 break;
00663 }
00664 }
00665 }
00666 $table_data = views_fetch_data($table);
00667
00668
00669 $handler = $table_data[$bundle_key]['filter']['handler'];
00670 if ($handler == 'views_handler_filter_in_operator' || is_subclass_of($handler, 'views_handler_filter_in_operator')) {
00671 $value = drupal_map_assoc(array($form_state['values']['show']['type']));
00672 }
00673 else {
00674 $value = $form_state['values']['show']['type'];
00675 }
00676
00677 $filters[$bundle_key] = array(
00678 'id' => $bundle_key,
00679 'table' => $table,
00680 'field' => $bundle_key,
00681 'value' => $value,
00682 );
00683 }
00684
00685
00686 if (!empty($form_state['values']['show']['tagged_with']['tids'])) {
00687 $filters['tid'] = array(
00688 'id' => 'tid',
00689 'table' => 'taxonomy_index',
00690 'field' => 'tid',
00691 'value' => $form_state['values']['show']['tagged_with']['tids'],
00692 'vocabulary' => $form_state['values']['show']['tagged_with']['vocabulary'],
00693 );
00694
00695
00696 if (count($form_state['values']['show']['tagged_with']['tids']) > 1) {
00697 $filters['tid']['operator'] = 'and';
00698
00699
00700 sort($filters['tid']['value']);
00701 }
00702 }
00703
00704 return $filters;
00705 }
00706
00707 protected function default_display_sorts($form, $form_state) {
00708 $sorts = array();
00709
00710
00711 if (isset($this->plugin['sorts'])) {
00712 foreach ($this->plugin['sorts'] as $name => $info) {
00713 $sorts[$name] = $info;
00714 }
00715 }
00716
00717
00718 $sorts = array_merge($sorts, $this->default_display_sorts_user($form, $form_state));
00719
00720 return $sorts;
00721 }
00722
00723 protected function default_display_sorts_user($form, $form_state) {
00724 $sorts = array();
00725
00726
00727 if (!empty($form_state['values']['show']['sort']) && $form_state['values']['show']['sort'] != 'none') {
00728 list($column, $sort) = explode(':', $form_state['values']['show']['sort']);
00729
00730 $column = explode('-', $column);
00731 if (count($column) > 1) {
00732 $table = $column[0];
00733 $column = $column[1];
00734 }
00735 else {
00736 $table = $this->base_table;
00737 $column = $column[0];
00738 }
00739
00740 $sorts[$column] = array(
00741 'id' => $column,
00742 'table' => $table,
00743 'field' => $column,
00744 'order' => $sort,
00745 );
00746 }
00747
00748 return $sorts;
00749 }
00750
00751 protected function page_display_options($form, $form_state) {
00752 $display_options = array();
00753 $page = $form_state['values']['page'];
00754 $display_options['title'] = $page['title'];
00755 $display_options['path'] = $page['path'];
00756 $display_options['style_plugin'] = $page['style']['style_plugin'];
00757
00758 $display_options['row_plugin'] = isset($page['style']['row_plugin']) ? $page['style']['row_plugin'] : 'fields';
00759 if (empty($page['items_per_page'])) {
00760 $display_options['pager']['type'] = 'none';
00761 }
00762 elseif ($page['pager']) {
00763 $display_options['pager']['type'] = 'full';
00764 }
00765 else {
00766 $display_options['pager']['type'] = 'some';
00767 }
00768 $display_options['pager']['options']['items_per_page'] = $page['items_per_page'];
00769 if (!empty($page['link'])) {
00770 $display_options['menu']['type'] = 'normal';
00771 $display_options['menu']['title'] = $page['link_properties']['title'];
00772 $display_options['menu']['name'] = $page['link_properties']['menu_name'];
00773 }
00774 return $display_options;
00775 }
00776
00777 protected function block_display_options($form, $form_state) {
00778 $display_options = array();
00779 $block = $form_state['values']['block'];
00780 $display_options['title'] = $block['title'];
00781 $display_options['style_plugin'] = $block['style']['style_plugin'];
00782 $display_options['row_plugin'] = isset($block['style']['row_plugin']) ? $block['style']['row_plugin'] : 'fields';
00783 $display_options['pager']['type'] = $block['pager'] ? 'full' : (empty($block['items_per_page']) ? 'none' : 'some');
00784 $display_options['pager']['options']['items_per_page'] = $block['items_per_page'];
00785 return $display_options;
00786 }
00787
00788 protected function page_feed_display_options($form, $form_state) {
00789 $display_options = array();
00790 $display_options['pager']['type'] = 'some';
00791 $display_options['style_plugin'] = 'rss';
00792 $display_options['row_plugin'] = $form_state['values']['page']['feed_properties']['row_plugin'];
00793 $display_options['path'] = $form_state['values']['page']['feed_properties']['path'];
00794 $display_options['title'] = $form_state['values']['page']['title'];
00795 $display_options['displays'] = array(
00796 'default' => 'default',
00797 'page' => 'page',
00798 );
00799 return $display_options;
00800 }
00801
00821 protected function set_default_options($options, $display, $default_display) {
00822 foreach ($options as $option => $value) {
00823
00824
00825 $default_value = $default_display->get_option($option);
00826 if (isset($default_value)) {
00827 $default_display->set_option($option, $value);
00828 }
00829 else {
00830 $display->set_option($option, $value);
00831 }
00832 }
00833 }
00834
00857 protected function set_override_options($options, $display, $default_display) {
00858 foreach ($options as $option => $value) {
00859
00860
00861 $default_value = $default_display->get_option($option);
00862 if (!isset($default_value)) {
00863 $display->set_option($option, $value);
00864 }
00865 elseif ($default_value !== $value) {
00866 $display->override_option($option, $value);
00867 }
00868 }
00869 }
00870
00871 protected function retrieve_validated_view($form, $form_state, $unset = TRUE) {
00872 $key = hash('sha256', serialize($form_state['values']));
00873 $view = (isset($this->validated_views[$key]) ? $this->validated_views[$key] : NULL);
00874 if ($unset) {
00875 unset($this->validated_views[$key]);
00876 }
00877 return $view;
00878 }
00879
00880 protected function set_validated_view($form, $form_state, $view) {
00881 $key = hash('sha256', serialize($form_state['values']));
00882 $this->validated_views[$key] = $view;
00883 }
00884
00888 function validate($form, &$form_state) {
00889 $view = $this->instantiate_view($form, $form_state);
00890 $errors = $view->validate();
00891 if (!is_array($errors) || empty($errors)) {
00892 $this->set_validated_view($form, $form_state, $view);
00893 return array();
00894 }
00895 return $errors;
00896 }
00897
00903 function create_view($form, &$form_state) {
00904 $view = $this->retrieve_validated_view($form, $form_state);
00905 if (empty($view)) {
00906 throw new ViewsWizardException(t('Attempted to create_view with values that have not been validated'));
00907 }
00908 return $view;
00909 }
00910
00911 }