From 76c51dc766dc53f1bb0909f3cf5d68081aea5b95 Mon Sep 17 00:00:00 2001 From: "tim.plunkett" <tim.plunkett@241634.no-reply.drupal.org> Date: Sun, 23 Sep 2012 20:16:12 +0200 Subject: [PATCH] Issue #1788266 by tim.plunkett, dawehner: Access the different views related properties on the right object. --- drush/views.drush.inc | 22 +- includes/admin.inc | 171 +++++----- .../views/Plugin/Type/ViewsPluginManager.php | 27 +- lib/Drupal/views/Plugin/views/area/Result.php | 2 +- lib/Drupal/views/Plugin/views/area/View.php | 2 +- .../views/argument/ArgumentPluginBase.php | 31 +- .../views/Plugin/views/argument/Date.php | 6 +- .../views/Plugin/views/argument/Null.php | 8 - .../Plugin/views/argument_validator/None.php | 41 +++ .../Plugin/views/cache/CachePluginBase.php | 6 +- .../views/display/DisplayPluginBase.php | 34 +- .../views/Plugin/views/display/Feed.php | 5 +- .../views/Plugin/views/display/Page.php | 6 +- .../exposed_form/ExposedFormPluginBase.php | 4 +- .../Plugin/views/field/FieldPluginBase.php | 14 +- .../Plugin/views/filter/FilterPluginBase.php | 20 +- lib/Drupal/views/Plugin/views/pager/Full.php | 2 +- lib/Drupal/views/Plugin/views/pager/Mini.php | 2 +- lib/Drupal/views/Plugin/views/query/Sql.php | 6 +- .../views/relationship/GroupwiseMax.php | 8 +- .../Plugin/views/style/StylePluginBase.php | 2 +- .../Plugin/views/wizard/WizardPluginBase.php | 4 +- lib/Drupal/views/Tests/AnalyzeTest.php | 1 - .../Tests/Field/HandlerFieldFieldTest.php | 60 ++-- .../views/Tests/Handler/FilterCombineTest.php | 2 +- .../Tests/Plugin/ArgumentDefaultTest.php | 2 +- lib/Drupal/views/Tests/Plugin/CacheTest.php | 10 +- lib/Drupal/views/Tests/Plugin/DisplayTest.php | 6 +- lib/Drupal/views/Tests/Plugin/FilterTest.php | 2 +- lib/Drupal/views/Tests/Plugin/PagerTest.php | 7 - lib/Drupal/views/Tests/UpgradeTestCase.php | 8 +- lib/Drupal/views/Tests/ViewExecutableTest.php | 9 - lib/Drupal/views/Tests/ViewStorageTest.php | 4 +- lib/Drupal/views/Tests/ViewTest.php | 6 +- lib/Drupal/views/Tests/ViewTestBase.php | 4 +- lib/Drupal/views/ViewExecutable.php | 296 ++++++++++++++---- lib/Drupal/views/ViewStorage.php | 282 ++--------------- .../block/Plugin/views/display/Block.php | 10 +- lib/Views/field/Plugin/views/field/Field.php | 2 +- .../node/Plugin/views/argument/CreatedDay.php | 16 +- .../Plugin/views/argument/CreatedFullDate.php | 18 +- .../Plugin/views/argument/CreatedMonth.php | 16 +- .../Plugin/views/argument/CreatedWeek.php | 10 +- .../Plugin/views/argument/CreatedYear.php | 10 +- .../views/argument/CreatedYearMonth.php | 18 +- tests/views_test_data/views_test_data.module | 4 +- theme/theme.inc | 16 +- theme/views-ui-edit-view.tpl.php | 2 +- views.module | 58 ++-- views.tokens.inc | 6 +- views_ui.module | 24 +- views_ui_listing/views_ui_listing.module | 2 +- 52 files changed, 622 insertions(+), 712 deletions(-) create mode 100644 lib/Drupal/views/Plugin/views/argument_validator/None.php diff --git a/drush/views.drush.inc b/drush/views.drush.inc index 438433939ae1..42aff0fb6d4e 100644 --- a/drush/views.drush.inc +++ b/drush/views.drush.inc @@ -124,7 +124,7 @@ function views_revert_views() { continue; } if ($view->type == dt('Overridden')) { - $overridden[$view->name] = $view->name; + $overridden[$view->storage->name] = $view->storage->name; } } @@ -220,14 +220,14 @@ function views_revert_view($view) { // Revert the view. $view->delete(); // Clear its cache. - views_temp_store()->delete($view->name); + views_temp_store()->delete($view->storage->name); // Give feedback. - $message = dt("Reverted the view '@viewname'", array('@viewname' => $view->name)); + $message = dt("Reverted the view '@viewname'", array('@viewname' => $view->storage->name)); drush_log($message, 'success'); // Reverted one more view. } else { - drush_set_error(dt("The view '@viewname' is not overridden.", array('@viewname' => $view->name))); + drush_set_error(dt("The view '@viewname' is not overridden.", array('@viewname' => $view->storage->name))); } } @@ -319,7 +319,7 @@ function drush_views_list() { foreach ($views as $id => $view) { // if options were specified, check that first // mismatch push the loop to the next view - if ($with_tags && !in_array($view->tag, $tags)) { + if ($with_tags && !in_array($view->storage->tag, $tags)) { continue; } if ($with_status && !$view->disabled == $status) { @@ -328,21 +328,21 @@ function drush_views_list() { if ($with_type && strtolower($view->type) !== $type[0]) { continue; } - if ($with_name && !stristr($view->name, $name[0])) { + if ($with_name && !stristr($view->storage->name, $name[0])) { continue; } $row = array(); // each row entry should be in the same order as the header - $row[] = $view->name; - $row[] = $view->description; + $row[] = $view->storage->name; + $row[] = $view->storage->description; $row[] = $view->type; - $row[] = $view->disabled ? dt('Disabled') : dt('Enabled'); - $row[] = $view->tag; + $row[] = $view->storage->disabled ? dt('Disabled') : dt('Enabled'); + $row[] = $view->storage->tag; // place the row in the appropiate array, // so we can have disabled views at the bottom - if ($view->disabled) { + if ($view->storage->disabled) { $disabled_views[] = $row; } else{ diff --git a/includes/admin.inc b/includes/admin.inc index 0bab69fc7dee..d81b87a863be 100644 --- a/includes/admin.inc +++ b/includes/admin.inc @@ -131,7 +131,7 @@ function views_ui_preview($view, $display_id, $args = array()) { } // Make view links come back to preview. - $view->override_path = 'admin/structure/views/nojs/preview/' . $view->name . '/' . $display_id; + $view->override_path = 'admin/structure/views/nojs/preview/' . $view->storage->name . '/' . $display_id; // Also override the current path so we get the pager. $original_path = current_path(); @@ -279,7 +279,7 @@ function views_ui_add_form($form, &$form_state) { '#title' => t('View name'), '#required' => TRUE, '#size' => 32, - '#default_value' => !empty($form_state['view']) ? $form_state['view']->human_name : '', + '#default_value' => !empty($form_state['view']) ? $form_state['view']->storage->getHumanName() : '', '#maxlength' => 255, ); $form['name'] = array( @@ -712,7 +712,7 @@ function views_ui_add_form_store_edit_submit($form, &$form_state) { $destination = drupal_get_destination(); $query->remove('destination'); } - $form_state['redirect'] = array('admin/structure/views/view/' . $view->name, array('query' => $destination)); + $form_state['redirect'] = array('admin/structure/views/view/' . $view->storage->name, array('query' => $destination)); } /** @@ -798,19 +798,19 @@ function views_ui_break_lock_confirm($form, &$form_state, $view) { $form = array(); if (empty($view->locked)) { - $form['message']['#markup'] = t('There is no lock on view %name to break.', array('%name' => $view->name)); + $form['message']['#markup'] = t('There is no lock on view %name to break.', array('%name' => $view->storage->name)); return $form; } $cancel = drupal_container()->get('request')->query->get('cancel'); if (empty($cancel)) { - $cancel = 'admin/structure/views/view/' . $view->name . '/edit'; + $cancel = 'admin/structure/views/view/' . $view->storage->name . '/edit'; } $account = user_load($view->locked->ownerId); return confirm_form($form, t('Are you sure you want to break the lock on view %name?', - array('%name' => $view->name)), + array('%name' => $view->storage->name)), $cancel, t('By breaking this lock, any unsaved changes made by !user will be lost!', array('!user' => theme('username', array('account' => $account)))), t('Break lock'), @@ -821,8 +821,8 @@ function views_ui_break_lock_confirm($form, &$form_state, $view) { * Submit handler to break_lock a view. */ function views_ui_break_lock_confirm_submit(&$form, &$form_state) { - UserTempStore::clearAll('view', $form_state['view']->name); - $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->name . '/edit'; + UserTempStore::clearAll('view', $form_state['view']->storage->name); + $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit'; drupal_set_message(t('The lock has been broken and you may now edit this view.')); } @@ -973,7 +973,7 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { $form['locked'] = array( '#theme_wrappers' => array('container'), '#attributes' => array('class' => array('view-locked', 'messages', 'warning')), - '#markup' => t('This view is being edited by user !user, and is therefore locked from editing by others. This lock is !age old. Click here to <a href="!break">break this lock</a>.', array('!user' => theme('username', array('account' => user_load($view->locked->ownerId))), '!age' => format_interval(REQUEST_TIME - $view->locked->updated), '!break' => url('admin/structure/views/view/' . $view->name . '/break-lock'))), + '#markup' => t('This view is being edited by user !user, and is therefore locked from editing by others. This lock is !age old. Click here to <a href="!break">break this lock</a>.', array('!user' => theme('username', array('account' => user_load($view->locked->ownerId))), '!age' => format_interval(REQUEST_TIME - $view->locked->updated), '!break' => url('admin/structure/views/view/' . $view->storage->name . '/break-lock'))), ); } if (isset($view->vid) && $view->vid == 'new') { @@ -1129,7 +1129,7 @@ function views_ui_preview_form($form, &$form_state, $view, $display_id = 'defaul '#id' => 'preview-submit', '#submit' => array('views_ui_edit_form_submit_preview'), '#ajax' => array( - 'path' => 'admin/structure/views/view/' . $view->name . '/preview/' . $display_id . '/ajax', + 'path' => 'admin/structure/views/view/' . $view->storage->name . '/preview/' . $display_id . '/ajax', 'wrapper' => 'views-preview-wrapper', 'event' => 'click', 'progress' => array('type' => 'throbber'), @@ -1141,7 +1141,7 @@ function views_ui_preview_form($form, &$form_state, $view, $display_id = 'defaul // we may need to split Preview into a separate form. '#process' => array_merge(array('views_ui_default_button'), element_info_property('submit', '#process', array())), ); - $form['#action'] = url('admin/structure/views/view/' . $view->name .'/preview/' . $display_id); + $form['#action'] = url('admin/structure/views/view/' . $view->storage->name .'/preview/' . $display_id); return $form; } @@ -1166,21 +1166,21 @@ function views_ui_render_display_top($view, $display_id) { '#links' => array( 'edit-details' => array( 'title' => t('edit view name/description'), - 'href' => "admin/structure/views/nojs/edit-details/$view->name", + 'href' => "admin/structure/views/nojs/edit-details/{$view->storage->name}", 'attributes' => array('class' => array('views-ajax-link')), ), 'analyze' => array( 'title' => t('analyze view'), - 'href' => "admin/structure/views/nojs/analyze/$view->name/$display_id", + 'href' => "admin/structure/views/nojs/analyze/{$view->storage->name}/$display_id", 'attributes' => array('class' => array('views-ajax-link')), ), 'clone' => array( 'title' => t('clone view'), - 'href' => "admin/structure/views/view/$view->name/clone", + 'href' => "admin/structure/views/view/{$view->storage->name}/clone", ), 'reorder' => array( 'title' => t('reorder displays'), - 'href' => "admin/structure/views/nojs/reorder-displays/$view->name/$display_id", + 'href' => "admin/structure/views/nojs/reorder-displays/{$view->storage->name}/$display_id", 'attributes' => array('class' => array('views-ajax-link')), ), ), @@ -1193,14 +1193,14 @@ function views_ui_render_display_top($view, $display_id) { if ($view->type == t('Overridden')) { $element['extra_actions']['#links']['revert'] = array( 'title' => t('revert view'), - 'href' => "admin/structure/views/view/$view->name/revert", - 'query' => array('destination' => "admin/structure/views/view/$view->name"), + 'href' => "admin/structure/views/view/{$view->storage->name}/revert", + 'query' => array('destination' => "admin/structure/views/view/{$view->storage->name}"), ); } else { $element['extra_actions']['#links']['delete'] = array( 'title' => t('delete view'), - 'href' => "admin/structure/views/view/$view->name/delete", + 'href' => "admin/structure/views/view/{$view->storage->name}/delete", ); } } @@ -1216,7 +1216,7 @@ function views_ui_render_display_top($view, $display_id) { } // Buttons for adding a new display. - foreach (views_fetch_plugin_names('display', NULL, array($view->base_table)) as $type => $label) { + foreach (views_fetch_plugin_names('display', NULL, array($view->storage->base_table)) as $type => $label) { $element['add_display'][$type] = array( '#type' => 'submit', '#value' => t('Add !display', array('!display' => $label)), @@ -1246,11 +1246,11 @@ function views_ui_edit_form_submit_add_display($form, &$form_state) { // Create the new display. $parents = $form_state['triggering_element']['#parents']; $display_type = array_pop($parents); - $display_id = $view->addDisplay($display_type); + $display_id = $view->storage->addDisplay($display_type); views_ui_cache_set($view); // Redirect to the new display's edit page. - $form_state['redirect'] = 'admin/structure/views/view/' . $view->name . '/edit/' . $display_id; + $form_state['redirect'] = 'admin/structure/views/view/' . $view->storage->name . '/edit/' . $display_id; } /** @@ -1262,9 +1262,9 @@ function views_ui_edit_form_submit_duplicate_display($form, &$form_state) { // Create the new display. $display = $view->display[$display_id]; - $new_display_id = $view->addDisplay($display['display_plugin']); - $view->display[$new_display_id] = clone $display; - $view->display[$new_display_id]['id'] = $new_display_id; + $new_display_id = $view->storage->addDisplay($display['display_plugin']); + $view->storage->display[$new_display_id] = clone $display; + $view->storage->display[$new_display_id]['id'] = $new_display_id; // By setting the current display the changed marker will appear on the new // display. @@ -1272,7 +1272,7 @@ function views_ui_edit_form_submit_duplicate_display($form, &$form_state) { views_ui_cache_set($view); // Redirect to the new display's edit page. - $form_state['redirect'] = 'admin/structure/views/view/' . $view->name . '/edit/' . $new_display_id; + $form_state['redirect'] = 'admin/structure/views/view/' . $view->storage->name . '/edit/' . $new_display_id; } /** @@ -1283,12 +1283,12 @@ function views_ui_edit_form_submit_delete_display($form, &$form_state) { $display_id = $form_state['display_id']; // Mark the display for deletion. - $view->display[$display_id]->deleted = TRUE; + $view->storage->display[$display_id]->deleted = TRUE; views_ui_cache_set($view); // Redirect to the top-level edit page. The first remaining display will // become the active display. - $form_state['redirect'] = 'admin/structure/views/view/' . $view->name; + $form_state['redirect'] = 'admin/structure/views/view/' . $view->storage->name; } /** @@ -1297,13 +1297,13 @@ function views_ui_edit_form_submit_delete_display($form, &$form_state) { function views_ui_edit_form_submit_undo_delete_display($form, &$form_state) { // Create the new display $id = $form_state['display_id']; - $form_state['view']->display[$id]->deleted = FALSE; + $form_state['view']->storage->display[$id]->deleted = FALSE; // Store in cache views_ui_cache_set($form_state['view']); // Redirect to the top-level edit page. - $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->name . '/edit/' . $id; + $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit/' . $id; } /** @@ -1318,7 +1318,7 @@ function views_ui_edit_form_submit_enable_display($form, &$form_state) { views_ui_cache_set($form_state['view']); // Redirect to the top-level edit page. - $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->name . '/edit/' . $id; + $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit/' . $id; } /** @@ -1332,7 +1332,7 @@ function views_ui_edit_form_submit_disable_display($form, &$form_state) { views_ui_cache_set($form_state['view']); // Redirect to the top-level edit page. - $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->name . '/edit/' . $id; + $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit/' . $id; } /** @@ -1340,7 +1340,7 @@ function views_ui_edit_form_submit_disable_display($form, &$form_state) { */ function views_ui_edit_form_submit_preview($form, &$form_state) { // Rebuild the form with a pristine $view object. - $form_state['build_info']['args'][0] = views_ui_cache_load($form_state['view']->name); + $form_state['build_info']['args'][0] = views_ui_cache_load($form_state['view']->storage->name); $form_state['show_preview'] = TRUE; $form_state['rebuild'] = TRUE; } @@ -1392,12 +1392,12 @@ function views_ui_edit_page_display_tabs($view, $display_id = NULL) { $tabs = array(); // Create a tab for each display. - foreach ($view->display as $id => $display) { + foreach ($view->storage->display as $id => $display) { $tabs[$id] = array( '#theme' => 'menu_local_task', '#link' => array( 'title' => views_ui_get_display_label($view, $id), - 'href' => 'admin/structure/views/view/' . $view->name . '/edit/' . $id, + 'href' => 'admin/structure/views/view/' . $view->storage->name . '/edit/' . $id, 'localized_options' => array(), ), ); @@ -1416,7 +1416,7 @@ function views_ui_edit_page_display_tabs($view, $display_id = NULL) { // Mark the display tab as red to show validation errors. $view->validate(); - foreach ($view->display as $id => $display) { + foreach ($view->storage->display as $id => $display) { if (!empty($view->display_errors[$id])) { // Always show the tab. $tabs[$id]['#access'] = TRUE; @@ -1437,7 +1437,7 @@ function views_ui_show_default_display($view) { $advanced_mode = config('views.settings')->get('ui.show.master_display'); // For other users, show the default display only if there are no others, and // hide it if there's at least one "real" display. - $additional_displays = (count($view->display) == 1); + $additional_displays = (count($view->displayHandlers) == 1); return $advanced_mode || $additional_displays; } @@ -1447,7 +1447,7 @@ function views_ui_show_default_display($view) { */ function views_ui_get_display_tab($view, $display_id) { $build = array(); - $display = $view->display[$display_id]; + $display = $view->displayHandlers[$display_id]; // If the plugin doesn't exist, display an error message instead of an edit // page. if (empty($display)) { @@ -1457,7 +1457,7 @@ function views_ui_get_display_tab($view, $display_id) { } // Build the content of the edit page. else { - $build['details'] = views_ui_get_display_tab_details($view, $display); + $build['details'] = views_ui_get_display_tab_details($view, $display->display); } // In AJAX context, views_ui_regenerate_tab() returns this outside of form // context, so hook_form_views_ui_edit_form_alter() is insufficient. @@ -1931,10 +1931,10 @@ function views_ui_import_validate($form, &$form_state) { } if ($form_state['values']['name']) { - $view->name = $form_state['values']['name']; + $view->storage->name = $form_state['values']['name']; } - $test = views_get_view($view->name); + $test = views_get_view($view->storage->name); if (!$form_state['values']['name_override']) { if ($test && $test->type != t('Default')) { form_set_error('', t('A view by that name already exists; please choose a different name')); @@ -2007,7 +2007,7 @@ function views_ui_import_validate($form, &$form_state) { function views_ui_import_submit($form, &$form_state) { // Store in cache and then go to edit. views_ui_cache_set($form_state['view']); - $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->name . '/edit'; + $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit'; } /** @@ -2032,17 +2032,17 @@ function views_ui_edit_view_form_validate($form, &$form_state) { */ function views_ui_edit_view_form_submit($form, &$form_state) { // Go through and remove displayed scheduled for removal. - foreach ($form_state['view']->display as $id => $display) { + foreach ($form_state['view']->displayHandlers as $id => $display) { if (!empty($display->deleted)) { - unset($form_state['view']->display[$id]); + unset($form_state['view']->displayHandlers[$id]); } } // Rename display ids if needed. - foreach ($form_state['view']->display as $id => $display) { - if (!empty($display['new_id'])) { - $form_state['view']->display[$id]['id'] = $display['new_id']; + foreach ($form_state['view']->displayHandlers as $id => $display) { + if (!empty($display->display['new_id'])) { + $form_state['view']->displayHandlers[$id]['id'] = $display['new_id']; // Redirect the user to the renamed display to be sure that the page itself exists and doesn't throw errors. - $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->name . '/edit/' . $display['new_id']; + $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit/' . $display['new_id']; } } @@ -2052,15 +2052,15 @@ function views_ui_edit_view_form_submit($form, &$form_state) { $destination = $query->get('destination'); if (!empty($destination)) { // Find out the first display which has a changed path and redirect to this url. - $old_view = views_get_view($form_state['view']->name); - foreach ($old_view->display as $id => $display) { + $old_view = views_get_view($form_state['view']->storage->name); + foreach ($old_view->displayHandlers as $id => $display) { // Only check for displays with a path. - if (!isset($display['display_options']['path'])) { + if (!isset($display->display['display_options']['path'])) { continue; } - $old_path = $display['display_options']['path']; - if (($display['display_plugin'] == 'page') && ($old_path == $destination) && ($old_path != $form_state['view']->display[$id]['display_options']['path'])) { - $destination = $form_state['view']->display[$id]['display_options']['path']; + $old_path = $display->display['display_options']['path']; + if (($display->display['display_plugin'] == 'page') && ($old_path == $destination) && ($old_path != $form_state['view']->display[$id]->display['display_options']['path'])) { + $destination = $form_state['view']->displayHandlers[$id]->display['display_options']['path']; $query->remove('destination'); } } @@ -2068,10 +2068,10 @@ function views_ui_edit_view_form_submit($form, &$form_state) { } $form_state['view']->save(); - drupal_set_message(t('The view %name has been saved.', array('%name' => $form_state['view']->getHumanName()))); + drupal_set_message(t('The view %name has been saved.', array('%name' => $form_state['view']->storage->getHumanName()))); // Remove this view from cache so we can edit it properly. - views_temp_store()->delete($form_state['view']->name); + views_temp_store()->delete($form_state['view']->storage->name); } /** @@ -2079,7 +2079,7 @@ function views_ui_edit_view_form_submit($form, &$form_state) { */ function views_ui_edit_view_form_cancel($form, &$form_state) { // Remove this view from cache so edits will be lost. - views_temp_store()->delete($form_state['view']->name); + views_temp_store()->delete($form_state['view']->storage->name); if (empty($form['view']->vid)) { // I seem to have to drupal_goto here because I can't get fapi to // honor the redirect target. Not sure what I screwed up here. @@ -2094,7 +2094,7 @@ function views_ui_edit_view_form_delete($form, &$form_state) { $request->remove('destination'); } // Redirect to the delete confirm page - $form_state['redirect'] = array('admin/structure/views/view/' . $form_state['view']->name . '/delete', array('query' => drupal_get_destination() + array('cancel' => 'admin/structure/views/view/' . $form_state['view']->name . '/edit'))); + $form_state['redirect'] = array('admin/structure/views/view/' . $form_state['view']->storage->name . '/delete', array('query' => drupal_get_destination() + array('cancel' => 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit'))); } /** @@ -2115,7 +2115,7 @@ function views_ui_edit_form_get_bucket($type, $view, $display) { // to get the right one. switch ($type) { case 'filter': - $rearrange_url = "admin/structure/views/nojs/rearrange-$type/$view->name/{$display['id']}/$type"; + $rearrange_url = "admin/structure/views/nojs/rearrange-$type/{$view->storage->name}/{$display['id']}/$type"; $rearrange_text = t('And/Or, Rearrange'); // TODO: Add another class to have another symbol for filter rearrange. $class = 'icon compact rearrange'; @@ -2135,7 +2135,7 @@ function views_ui_edit_form_get_bucket($type, $view, $display) { } default: - $rearrange_url = "admin/structure/views/nojs/rearrange/$view->name/{$display['id']}/$type"; + $rearrange_url = "admin/structure/views/nojs/rearrange/{$view->storage->name}/{$display['id']}/$type"; $rearrange_text = t('Rearrange'); $class = 'icon compact rearrange'; } @@ -2145,7 +2145,7 @@ function views_ui_edit_form_get_bucket($type, $view, $display) { $count_handlers = count($view->displayHandlers[$display['id']]->getHandlers($type)); $actions['add'] = array( 'title' => t('Add'), - 'href' => "admin/structure/views/nojs/add-item/$view->name/{$display['id']}/$type", + 'href' => "admin/structure/views/nojs/add-item/{$view->storage->name}/{$display['id']}/$type", 'attributes' => array('class' => array('icon compact add', 'views-ajax-link'), 'title' => t('Add'), 'id' => 'views-add-' . $type), 'html' => TRUE, ); @@ -2180,7 +2180,7 @@ function views_ui_edit_form_get_bucket($type, $view, $display) { // If there's an options form for the bucket, link to it. if (!empty($types[$type]['options'])) { - $build['#title'] = l($build['#title'], "admin/structure/views/nojs/config-type/$view->name/{$display['id']}/$type", array('attributes' => array('class' => array('views-ajax-link'), 'id' => 'views-title-' . $type))); + $build['#title'] = l($build['#title'], "admin/structure/views/nojs/config-type/{$view->storage->name}/{$display['id']}/$type", array('attributes' => array('class' => array('views-ajax-link'), 'id' => 'views-title-' . $type))); } static $relationships = NULL; @@ -2217,7 +2217,7 @@ function views_ui_edit_form_get_bucket($type, $view, $display) { if (empty($handler)) { $build['fields'][$id]['#class'][] = 'broken'; $field_name = t('Broken/missing handler: @table > @field', array('@table' => $field['table'], '@field' => $field['field'])); - $build['fields'][$id]['#link'] = l($field_name, "admin/structure/views/nojs/config-item/$view->name/{$display['id']}/$type/$id", array('attributes' => array('class' => array('views-ajax-link')), 'html' => TRUE)); + $build['fields'][$id]['#link'] = l($field_name, "admin/structure/views/nojs/config-item/{$view->storage->name}/{$display['id']}/$type/$id", array('attributes' => array('class' => array('views-ajax-link')), 'html' => TRUE)); continue; } @@ -2232,15 +2232,15 @@ function views_ui_edit_form_get_bucket($type, $view, $display) { if (!empty($field['exclude'])) { $link_attributes['class'][] = 'views-field-excluded'; } - $build['fields'][$id]['#link'] = l($link_text, "admin/structure/views/nojs/config-item/$view->name/{$display['id']}/$type/$id", array('attributes' => $link_attributes, 'html' => TRUE)); + $build['fields'][$id]['#link'] = l($link_text, "admin/structure/views/nojs/config-item/{$view->storage->name}/{$display['id']}/$type/$id", array('attributes' => $link_attributes, 'html' => TRUE)); $build['fields'][$id]['#class'][] = drupal_clean_css_identifier($display['id']. '-' . $type . '-' . $id); if ($view->displayHandlers[$display['id']]->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)); + $build['fields'][$id]['#settings_links'][] = l('<span class="label">' . t('Aggregation settings') . '</span>', "admin/structure/views/nojs/config-item-group/{$view->storage->name}/{$display['id']}/$type/$id", array('attributes' => array('class' => 'views-button-configure views-ajax-link', 'title' => t('Aggregation settings')), 'html' => TRUE)); } 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)); + $build['fields'][$id]['#settings_links'][] = l('<span class="label">' . t('Settings') . '</span>', "admin/structure/views/nojs/config-item-extra/{$view->storage->name}/{$display['id']}/$type/$id", array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => t('Settings')), 'html' => TRUE)); } if ($grouping) { @@ -2506,7 +2506,7 @@ function views_ui_standard_cancel($form, &$form_state) { views_ui_cache_set($form_state['view']); } - $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->name . '/edit'; + $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit'; } /** @@ -2518,7 +2518,7 @@ function views_ui_standard_display_dropdown(&$form, &$form_state, $section) { $view = &$form_state['view']; $display_id = $form_state['display_id']; $displays = $view->displayHandlers; - $current_display = $view->displayHandlers[$display_id]; + $current_display = $view->display_handler; // Add the "2 of 3" progress indicator. // @TODO: Move this to a separate function if it's needed on any forms that @@ -2678,7 +2678,7 @@ function views_ui_build_identifier($key, $view, $display_id, $args) { $form = views_ui_ajax_forms($key); // Automatically remove the single-form cache if it exists and // does not match the key. - $identifier = implode('-', array($key, $view->name, $display_id)); + $identifier = implode('-', array($key, $view->storage->name, $display_id)); foreach ($form['args'] as $id) { $arg = (!empty($args)) ? array_shift($args) : NULL; @@ -2717,7 +2717,7 @@ function views_ui_build_form_state($js, $key, &$view, $display_id, $args) { function views_ui_build_form_url($form_state) { $form = views_ui_ajax_forms($form_state['form_key']); $ajax = empty($form_state['ajax']) ? 'nojs' : 'ajax'; - $name = $form_state['view']->name; + $name = $form_state['view']->storage->name; $url = "admin/structure/views/$ajax/$form_state[form_key]/$name/$form_state[display_id]"; foreach ($form['args'] as $arg) { $url .= '/' . $form_state[$arg]; @@ -2834,7 +2834,7 @@ function views_ui_ajax_form($js, $key, $view, $display_id = '') { } elseif (!$js) { // if nothing on the stack, non-js forms just go back to the main view editor. - return drupal_goto("admin/structure/views/view/$view->name/edit"); + return drupal_goto("admin/structure/views/view/{$view->storage->name}/edit"); } else { $output = array(); @@ -2895,7 +2895,7 @@ function views_ui_analyze_view_form($form, &$form_state) { * Submit handler for views_ui_analyze_view_form */ function views_ui_analyze_view_form_submit($form, &$form_state) { - $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->name . '/edit'; + $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit'; } /** @@ -2954,7 +2954,7 @@ function views_ui_reorder_displays_form($form, &$form_state) { 'limit' => 0, ); - $form['#action'] = url('admin/structure/views/nojs/reorder-displays/' . $view->name . '/' . $display_id); + $form['#action'] = url('admin/structure/views/nojs/reorder-displays/' . $view->storage->name . '/' . $display_id); views_ui_standard_form_buttons($form, $form_state, 'views_ui_reorder_displays_form'); @@ -3014,7 +3014,7 @@ function views_ui_reorder_displays_form_submit($form, &$form_state) { // Store in cache views_ui_cache_set($form_state['view']); - $form_state['redirect'] = array('admin/structure/views/view/' . $form_state['view']->name . '/edit', array('fragment' => 'views-tab-default')); + $form_state['redirect'] = array('admin/structure/views/view/' . $form_state['view']->storage->name . '/edit', array('fragment' => 'views-tab-default')); } /** @@ -3092,20 +3092,20 @@ function views_ui_edit_details_form($form, &$form_state) { '#type' => 'textfield', '#title' => t('Human-readable name'), '#description' => t('A descriptive human-readable name for this view. Spaces are allowed'), - '#default_value' => $view->getHumanName(), + '#default_value' => $view->storage->getHumanName(), ); $form['details']['tag'] = array( '#type' => 'textfield', '#title' => t('View tag'), '#description' => t('Optionally, enter a comma delimited list of tags for this view to use in filtering and sorting views on the administrative page.'), - '#default_value' => $view->tag, + '#default_value' => $view->storage->tag, '#autocomplete_path' => 'admin/views/ajax/autocomplete/tag', ); $form['details']['description'] = array( '#type' => 'textfield', '#title' => t('View description'), '#description' => t('This description will appear on the Views administrative UI to tell you what the view is about.'), - '#default_value' => $view->description, + '#default_value' => $view->storage->description, ); views_ui_standard_form_buttons($form, $form_state, 'views_ui_edit_details_form'); @@ -3139,14 +3139,13 @@ function views_ui_edit_display_form($form, &$form_state) { if (!$view->setDisplay($display_id)) { views_ajax_error(t('Invalid display id @display', array('@display' => $display_id))); } - $display = &$view->display[$display_id]; // Get form from the handler. $form['options'] = array( '#theme_wrappers' => array('container'), '#attributes' => array('class' => array('scroll')), ); - $view->displayHandlers[$display['id']]->buildOptionsForm($form['options'], $form_state); + $view->display_handler->buildOptionsForm($form['options'], $form_state); // The handler options form sets $form['#title'], which we need on the entire // $form instead of just the ['options'] section. @@ -3521,8 +3520,8 @@ function views_ui_rearrange_filter_form($form, &$form_state) { if (!$view->setDisplay($display_id)) { views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); } - $display = &$view->display[$display_id]; - $form['#title'] = check_plain($view->display[$display_id]['display_title']) . ': '; + $display = $view->displayHandlers[$display_id]; + $form['#title'] = check_plain($display->display['display_title']) . ': '; $form['#title'] .= t('Rearrange @type', array('@type' => $types[$type]['ltitle'])); $form['#section'] = $display_id . 'rearrange-item'; @@ -4939,8 +4938,8 @@ function views_ui_autocomplete_tag($string = '') { // get matches from default views: $views = views_get_all_views(); foreach ($views as $view) { - if (!empty($view->tag) && strpos($view->tag, $string) === 0) { - $matches[$view->tag] = $view->tag; + if (!empty($view->storage->tag) && strpos($view->storage->tag, $string) === 0) { + $matches[$view->storage->tag] = $view->storage->tag; if (count($matches) >= 10) { break; } @@ -5202,7 +5201,7 @@ function theme_views_ui_style_plugin_table($variables) { * @todo Remove this function once editing the display title is possible. */ function views_ui_get_display_label($view, $display_id, $check_changed = TRUE) { - $title = $display_id == 'default' ? t('Master') : $view->display[$display_id]['display_title']; + $title = $display_id == 'default' ? t('Master') : $view->storage->display[$display_id]['display_title']; $title = views_ui_truncate($title, 25); if ($check_changed && !empty($view->changed_display[$display_id])) { @@ -5287,7 +5286,9 @@ function views_ui_field_list() { // Therefore search in all views, displays and handler-types. $fields = array(); foreach ($views as $view) { - foreach ($view->display as $display_id => $display) { + $view = $view->getExecutable(); + $view->initDisplay(); + foreach ($view->displayHandlers as $display_id => $display) { if ($view->setDisplay($display_id)) { foreach (ViewExecutable::viewsHandlerTypes() as $type => $info) { foreach ($view->getItems($type, $display_id) as $item) { @@ -5296,7 +5297,7 @@ function views_ui_field_list() { && $data = $data[$item['field']][$type]) { // The final check that we have a fieldapi field now. if (isset($data['field_name'])) { - $fields[$data['field_name']][$view->name] = $view->name; + $fields[$data['field_name']][$view->storage->name] = $view->storage->name; } } } diff --git a/lib/Drupal/views/Plugin/Type/ViewsPluginManager.php b/lib/Drupal/views/Plugin/Type/ViewsPluginManager.php index 7b7102b9ce03..535ac61826f8 100644 --- a/lib/Drupal/views/Plugin/Type/ViewsPluginManager.php +++ b/lib/Drupal/views/Plugin/Type/ViewsPluginManager.php @@ -14,13 +14,6 @@ class ViewsPluginManager extends PluginManagerBase { - /** - * The handler type of this plugin manager, for example filter or field. - * - * @var string - */ - protected $type; - /** * A list of Drupal core modules. * @@ -32,11 +25,13 @@ public function __construct($type) { // @todo Remove this hack in http://drupal.org/node/1708404. views_init(); - $this->type = $type; - - $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', $this->type), 'views:' . $this->type, 'views'); + $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', $type), 'views:' . $type, 'views'); $this->factory = new DefaultFactory($this); $this->coreModules = views_core_modules(); + $this->defaults += array( + 'parent' => 'parent', + 'plugin_type' => $type, + ); } /** @@ -45,23 +40,17 @@ public function __construct($type) { public function processDefinition(&$definition, $plugin_id) { parent::processDefinition($definition, $plugin_id); - // If someone adds an invalid plugin ID, don't provide defaults. - // views_get_plugin() will then don't createInstance. - if (empty($definition)) { - return; - } - $module = isset($definition['module']) ? $definition['module'] : 'views'; // If this module is a core module, use views as the module directory. $module_dir = in_array($module, $this->coreModules) ? 'views' : $module; + $theme_path = drupal_get_path('module', $module_dir); // Setup automatic path/file finding for theme registration. if ($module_dir == 'views') { - $theme_path = drupal_get_path('module', $module_dir) . '/theme'; + $theme_path .= '/theme'; $theme_file = 'theme.inc'; } else { - $theme_path = $path = drupal_get_path('module', $module_dir); $theme_file = "$module.views.inc"; } @@ -69,8 +58,6 @@ public function processDefinition(&$definition, $plugin_id) { 'module' => $module_dir, 'theme path' => $theme_path, 'theme file' => $theme_file, - 'parent' => 'parent', - 'plugin_type' => $this->type, ); } diff --git a/lib/Drupal/views/Plugin/views/area/Result.php b/lib/Drupal/views/Plugin/views/area/Result.php index 6bf0732aa6e8..11a5f94070dd 100644 --- a/lib/Drupal/views/Plugin/views/area/Result.php +++ b/lib/Drupal/views/Plugin/views/area/Result.php @@ -73,7 +73,7 @@ function render($empty = FALSE) { // @TODO: Maybe use a possible is views empty functionality. // Not every view has total_rows set, use view->result instead. $total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result); - $name = check_plain($this->view->human_name); + $name = check_plain($this->view->storage->getHumanName()); if ($per_page === 0) { $page_count = 1; $start = 1; diff --git a/lib/Drupal/views/Plugin/views/area/View.php b/lib/Drupal/views/Plugin/views/area/View.php index 0c589b81d6e2..018996c29608 100644 --- a/lib/Drupal/views/Plugin/views/area/View.php +++ b/lib/Drupal/views/Plugin/views/area/View.php @@ -35,7 +35,7 @@ protected function defineOptions() { public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); - $view_display = $this->view->name . ':' . $this->view->current_display; + $view_display = $this->view->storage->name . ':' . $this->view->current_display; $options = array('' => t('-Select-')); $options += views_get_views_as_options(FALSE, 'all', $view_display, FALSE, TRUE); diff --git a/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php b/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php index b8a1fcf2f819..4676b72c3f2d 100644 --- a/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php +++ b/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php @@ -301,7 +301,6 @@ public function buildOptionsForm(&$form, &$form_state) { ), ); - $validate_types = array('none' => t('- Basic validation -')); $plugins = views_get_plugin_definitions('argument_validator'); foreach ($plugins as $id => $info) { if (!empty($info['no_ui'])) { @@ -946,17 +945,8 @@ public function validateArgument($arg) { return $this->argument_validated = TRUE; } - if ($this->options['validate']['type'] == 'none') { - return $this->argument_validated = $this->validate_argument_basic($arg); - } - $plugin = $this->get_plugin('argument_validator'); - if ($plugin) { - return $this->argument_validated = $plugin->validate_argument($arg); - } - - // If the plugin isn't found, fall back to the basic validation path: - return $this->argument_validated = $this->validate_argument_basic($arg); + return $this->argument_validated = $plugin->validate_argument($arg); } /** @@ -984,25 +974,6 @@ function validate_argument($arg) { return $rc; } - /** - * Provide a basic argument validation. - * - * This can be overridden for more complex types; the basic - * validator only checks to see if the argument is not NULL - * or is numeric if the definition says it's numeric. - */ - function validate_argument_basic($arg) { - if (!isset($arg) || $arg === '') { - return FALSE; - } - - if (!empty($this->definition['numeric']) && !isset($this->options['break_phrase']) && !is_numeric($arg)) { - return FALSE; - } - - return TRUE; - } - /** * Set the input for this argument * diff --git a/lib/Drupal/views/Plugin/views/argument/Date.php b/lib/Drupal/views/Plugin/views/argument/Date.php index e136b2c230c0..183011a656d3 100644 --- a/lib/Drupal/views/Plugin/views/argument/Date.php +++ b/lib/Drupal/views/Plugin/views/argument/Date.php @@ -51,7 +51,7 @@ function default_argument_form(&$form, &$form_state) { */ function get_default_argument($raw = FALSE) { if (!$raw && $this->options['default_argument_type'] == 'date') { - return date($this->arg_format, REQUEST_TIME); + return date($this->definition['format'], REQUEST_TIME); } elseif (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) { foreach (range(1, 3) as $i) { @@ -69,10 +69,10 @@ function get_default_argument($raw = FALSE) { return parent::get_default_argument(); } elseif ($this->options['default_argument_type'] == 'node_created') { - return date($this->arg_format, $node->created); + return date($this->definition['format'], $node->created); } elseif ($this->options['default_argument_type'] == 'node_changed') { - return date($this->arg_format, $node->changed); + return date($this->definition['format'], $node->changed); } } diff --git a/lib/Drupal/views/Plugin/views/argument/Null.php b/lib/Drupal/views/Plugin/views/argument/Null.php index ce998cc235e9..6097b0029f4e 100644 --- a/lib/Drupal/views/Plugin/views/argument/Null.php +++ b/lib/Drupal/views/Plugin/views/argument/Null.php @@ -60,14 +60,6 @@ function default_actions($which = NULL) { return $actions; } - function validate_argument_basic($arg) { - if (!empty($this->options['must_not_be'])) { - return !isset($arg); - } - - return parent::validate_argument_basic($arg); - } - /** * Override the behavior of query() to prevent the query * from being changed in any way. diff --git a/lib/Drupal/views/Plugin/views/argument_validator/None.php b/lib/Drupal/views/Plugin/views/argument_validator/None.php new file mode 100644 index 000000000000..f15fc111ae54 --- /dev/null +++ b/lib/Drupal/views/Plugin/views/argument_validator/None.php @@ -0,0 +1,41 @@ +<?php + +/** + * @file + * Definition of Drupal\views\Plugin\views\argument_validator\None. + */ + +namespace Drupal\views\Plugin\views\argument_validator; + +use Drupal\Core\Annotation\Plugin; +use Drupal\Core\Annotation\Translation; + +/** + * Do not validate the argument. + * + * @ingroup views_argument_validate_plugins + * + * @Plugin( + * id = "none", + * title = @Translation(" - Basic validation - ") + * ) + */ +class None extends ArgumentValidatorPluginBase { + + function validate_argument($argument) { + if (!empty($this->argument->options['must_not_be'])) { + return !isset($argument); + } + + if (!isset($argument) || $argument === '') { + return FALSE; + } + + if (!empty($this->argument->definition['numeric']) && !isset($this->argument->options['break_phrase']) && !is_numeric($arg)) { + return FALSE; + } + + return TRUE; + } + +} diff --git a/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php b/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php index 014acb8f4dcd..9f45b7c55c75 100644 --- a/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php +++ b/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php @@ -177,7 +177,7 @@ function cache_get($type) { * to be sure that we catch everything. Maybe that's a bad idea. */ function cache_flush() { - cache($this->table)->deletePrefix($this->view->name . ':'); + cache($this->table)->deletePrefix($this->view->storage->name . ':'); } /** @@ -302,7 +302,7 @@ function get_results_key() { } } - $this->_results_key = $this->view->name . ':' . $this->displayHandler->display['id'] . ':results:' . md5(serialize($key_data)); + $this->_results_key = $this->view->storage->name . ':' . $this->displayHandler->display['id'] . ':results:' . md5(serialize($key_data)); } return $this->_results_key; @@ -320,7 +320,7 @@ function get_output_key() { 'base_url' => $GLOBALS['base_url'], ); - $this->_output_key = $this->view->name . ':' . $this->displayHandler->display['id'] . ':output:' . md5(serialize($key_data)); + $this->_output_key = $this->view->storage->name . ':' . $this->displayHandler->display['id'] . ':output:' . md5(serialize($key_data)); } return $this->_output_key; diff --git a/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index 0ca5f5db4569..d58354d0998d 100644 --- a/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -85,7 +85,7 @@ abstract class DisplayPluginBase extends PluginBase { */ protected $usesAttachments = FALSE; - public function init(&$view, &$display, $options = NULL) { + public function init(ViewExecutable $view, &$display, $options = NULL) { $this->setOptionDefaults($this->options, $this->defineOptions()); $this->view = &$view; $this->display = &$display; @@ -769,7 +769,7 @@ public function getPlugin($type = 'style', $name = NULL) { break; case 'query': - $views_data = views_fetch_data($this->view->base_table); + $views_data = views_fetch_data($this->view->storage->base_table); $name = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query'; default: $option_name = $type; @@ -806,10 +806,10 @@ public function getPlugin($type = 'style', $name = NULL) { $display_id = $this->isDefaulted($option_name) ? $this->display['id'] : 'default'; if (!isset($this->base_field)) { - $views_data = views_fetch_data($this->view->base_table); - $this->view->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : ''; + $views_data = views_fetch_data($this->view->storage->base_table); + $this->view->storage->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : ''; } - $plugin->init($this->view->base_table, $this->view->base_field, $options); + $plugin->init($this->view->storage->base_table, $this->view->storage->base_field, $options); } $cache[$type][$name] = $plugin; } @@ -980,7 +980,7 @@ public function optionLink($text, $section, $class = '', $title = '') { $title = $text; } - return l($text, 'admin/structure/views/nojs/display/' . $this->view->name . '/' . $this->display['id'] . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE)); + return l($text, 'admin/structure/views/nojs/display/' . $this->view->storage->name . '/' . $this->display['id'] . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE)); } /** @@ -1478,7 +1478,7 @@ public function buildOptionsForm(&$form, &$form_state) { $access = $this->getOption('access'); $form['access']['type'] = array( '#type' => 'radios', - '#options' => views_fetch_plugin_names('access', NULL, array($this->view->base_table)), + '#options' => views_fetch_plugin_names('access', NULL, array($this->view->storage->base_table)), '#default_value' => $access['type'], ); @@ -1518,7 +1518,7 @@ public function buildOptionsForm(&$form, &$form_state) { $cache = $this->getOption('cache'); $form['cache']['type'] = array( '#type' => 'radios', - '#options' => views_fetch_plugin_names('cache', NULL, array($this->view->base_table)), + '#options' => views_fetch_plugin_names('cache', NULL, array($this->view->storage->base_table)), '#default_value' => $cache['type'], ); @@ -1584,7 +1584,7 @@ public function buildOptionsForm(&$form, &$form_state) { // Doesn't make sense to show a field setting here if we aren't querying // an entity base table. Also, we make sure that there's at least one // entity type with a translation handler attached. - if (in_array($this->view->base_table, $entity_tables) && $has_translation_handlers) { + if (in_array($this->view->storage->base_table, $entity_tables) && $has_translation_handlers) { $languages = array( '***CURRENT_LANGUAGE***' => t("Current user's language"), '***DEFAULT_LANGUAGE***' => t("Default site language"), @@ -1613,7 +1613,7 @@ public function buildOptionsForm(&$form, &$form_state) { $form['#title'] .= t('How should this view be styled'); $form['style_plugin'] = array( '#type' => 'radios', - '#options' => views_fetch_plugin_names('style', $this->getStyleType(), array($this->view->base_table)), + '#options' => views_fetch_plugin_names('style', $this->getStyleType(), array($this->view->storage->base_table)), '#default_value' => $this->getOption('style_plugin'), '#description' => t('If the style you choose has settings, be sure to click the settings button that will appear next to it in the View summary.'), ); @@ -1654,7 +1654,7 @@ public function buildOptionsForm(&$form, &$form_state) { $form['#title'] .= t('How should each row in this view be styled'); $form['row_plugin'] = array( '#type' => 'radios', - '#options' => views_fetch_plugin_names('row', $this->getStyleType(), array($this->view->base_table)), + '#options' => views_fetch_plugin_names('row', $this->getStyleType(), array($this->view->storage->base_table)), '#default_value' => $this->getOption('row_plugin'), ); @@ -1843,7 +1843,7 @@ public function buildOptionsForm(&$form, &$form_state) { '#markup' => '<div class="form-item description"><p>' . t('This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold.') . '</p></div>', ); - if (isset($this->view->display[$this->view->current_display]->new_id)) { + if (isset($this->view->display_handler->new_id)) { $form['important']['new_id'] = array( '#prefix' => '<div class="description">', '#suffix' => '</div>', @@ -2012,7 +2012,7 @@ public function buildOptionsForm(&$form, &$form_state) { $exposed_form = $this->getOption('exposed_form'); $form['exposed_form']['type'] = array( '#type' => 'radios', - '#options' => views_fetch_plugin_names('exposed_form', NULL, array($this->view->base_table)), + '#options' => views_fetch_plugin_names('exposed_form', NULL, array($this->view->storage->base_table)), '#default_value' => $exposed_form['type'], ); @@ -2046,7 +2046,7 @@ public function buildOptionsForm(&$form, &$form_state) { $pager = $this->getOption('pager'); $form['pager']['type'] = array( '#type' => 'radios', - '#options' => views_fetch_plugin_names('pager', !$this->usesPager() ? 'basic' : NULL, array($this->view->base_table)), + '#options' => views_fetch_plugin_names('pager', !$this->usesPager() ? 'basic' : NULL, array($this->view->storage->base_table)), '#default_value' => $pager['type'], ); @@ -2465,7 +2465,7 @@ public function renderMoreLink() { if (!empty($this->view->exposed_raw_input)) { $url_options['query'] = $this->view->exposed_raw_input; } - $theme = views_theme_functions('views_more', $this->view, $this->view->display[$this->view->current_display]); + $theme = views_theme_functions('views_more', $this->view, $this->view->display_handler->display); $path = check_url(url($path, $url_options)); return theme($theme, array('more_url' => $path, 'link_text' => check_plain($this->useMoreText()), 'view' => $this->view)); @@ -2690,8 +2690,8 @@ public function getSpecialBlocks() { $blocks = array(); if ($this->usesExposedFormInBlock()) { - $delta = '-exp-' . $this->view->name . '-' . $this->display['id']; - $desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->name, '@display_id' => $this->display['id'])); + $delta = '-exp-' . $this->view->storage->name . '-' . $this->display['id']; + $desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->storage->name, '@display_id' => $this->display['id'])); $blocks[$delta] = array( 'info' => $desc, diff --git a/lib/Drupal/views/Plugin/views/display/Feed.php b/lib/Drupal/views/Plugin/views/display/Feed.php index 0050f940d8d7..dbc2ab38a99e 100644 --- a/lib/Drupal/views/Plugin/views/display/Feed.php +++ b/lib/Drupal/views/Plugin/views/display/Feed.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\display; +use Drupal\views\ViewExecutable; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Drupal\Core\Annotation\Plugin; @@ -43,13 +44,13 @@ class Feed extends Page { */ protected $usesPager = FALSE; - public function init(&$view, &$display, $options = NULL) { + public function init(ViewExecutable $view, &$display, $options = NULL) { parent::init($view, $display, $options); // Set the default row style. Ideally this would be part of the option // definition, but in this case it's dependent on the view's base table, // which we don't know until init(). - $row_plugins = views_fetch_plugin_names('row', $this->getStyleType(), array($view->base_table)); + $row_plugins = views_fetch_plugin_names('row', $this->getStyleType(), array($view->storage->base_table)); $default_row_plugin = key($row_plugins); if ($this->options['row_plugin'] == '') { $this->options['row_plugin'] = $default_row_plugin; diff --git a/lib/Drupal/views/Plugin/views/display/Page.php b/lib/Drupal/views/Plugin/views/display/Page.php index e959f60a27ab..d348872334ca 100644 --- a/lib/Drupal/views/Plugin/views/display/Page.php +++ b/lib/Drupal/views/Plugin/views/display/Page.php @@ -80,7 +80,7 @@ public function executeHookMenu($callbacks) { // views_arg_load -- which lives in views.module $bits = explode('/', $this->getOption('path')); - $page_arguments = array($this->view->name, $this->display['id']); + $page_arguments = array($this->view->storage->name, $this->display['id']); $this->view->initHandlers(); $view_arguments = $this->view->argument; @@ -141,7 +141,7 @@ public function executeHookMenu($callbacks) { 'access callback' => 'views_access', 'access arguments' => $access_arguments, // Identify URL embedded arguments and correlate them to a handler - 'load arguments' => array($this->view->name, $this->display['id'], '%index'), + 'load arguments' => array($this->view->storage->name, $this->display['id'], '%index'), ); $menu = $this->getOption('menu'); if (empty($menu)) { @@ -202,7 +202,7 @@ public function executeHookMenu($callbacks) { 'access callback' => 'views_access', 'access arguments' => $access_arguments, // Identify URL embedded arguments and correlate them to a handler - 'load arguments' => array($this->view->name, $this->display['id'], '%index'), + 'load arguments' => array($this->view->storage->name, $this->display['id'], '%index'), 'title' => $tab_options['title'], 'description' => $tab_options['description'], 'menu_name' => $tab_options['name'], diff --git a/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php b/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php index c630167bff58..1bafe9eae863 100644 --- a/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -314,8 +314,8 @@ function reset_form(&$form, &$form_state) { // remember settings. $display_id = ($this->view->display_handler->isDefaulted('filters')) ? 'default' : $this->view->current_display; - if (isset($_SESSION['views'][$this->view->name][$display_id])) { - unset($_SESSION['views'][$this->view->name][$display_id]); + if (isset($_SESSION['views'][$this->view->storage->name][$display_id])) { + unset($_SESSION['views'][$this->view->storage->name][$display_id]); } // Set the form to allow redirect. diff --git a/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php b/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php index 5bc6f954b2f4..706f4135de59 100644 --- a/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php +++ b/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php @@ -1605,22 +1605,22 @@ public function themeFunctions() { $themes = array(); $hook = 'views_view_field'; - $display = $this->view->display[$this->view->current_display]; + $display = $this->view->display_handler->display; if (!empty($display)) { - $themes[] = $hook . '__' . $this->view->name . '__' . $display['id'] . '__' . $this->options['id']; - $themes[] = $hook . '__' . $this->view->name . '__' . $display['id']; + $themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['id'] . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['id']; $themes[] = $hook . '__' . $display['id'] . '__' . $this->options['id']; $themes[] = $hook . '__' . $display['id']; if ($display['id'] != $display['display_plugin']) { - $themes[] = $hook . '__' . $this->view->name . '__' . $display['display_plugin'] . '__' . $this->options['id']; - $themes[] = $hook . '__' . $this->view->name . '__' . $display['display_plugin']; + $themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['display_plugin'] . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['display_plugin']; $themes[] = $hook . '__' . $display['display_plugin'] . '__' . $this->options['id']; $themes[] = $hook . '__' . $display['display_plugin']; } } - $themes[] = $hook . '__' . $this->view->name . '__' . $this->options['id']; - $themes[] = $hook . '__' . $this->view->name; + $themes[] = $hook . '__' . $this->view->storage->name . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->storage->name; $themes[] = $hook . '__' . $this->options['id']; $themes[] = $hook; diff --git a/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php b/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php index 37a976851ea5..aba949a9c8e5 100644 --- a/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php +++ b/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php @@ -1240,8 +1240,8 @@ function store_group_input($input, $status) { // false means that we got a setting that means to recuse ourselves, // so we should erase whatever happened to be there. - if ($status === FALSE && isset($_SESSION['views'][$this->view->name][$display_id])) { - $session = &$_SESSION['views'][$this->view->name][$display_id]; + if ($status === FALSE && isset($_SESSION['views'][$this->view->storage->name][$display_id])) { + $session = &$_SESSION['views'][$this->view->storage->name][$display_id]; if (isset($session[$this->options['group_info']['identifier']])) { unset($session[$this->options['group_info']['identifier']]); @@ -1249,11 +1249,11 @@ function store_group_input($input, $status) { } if ($status !== FALSE) { - if (!isset($_SESSION['views'][$this->view->name][$display_id])) { - $_SESSION['views'][$this->view->name][$display_id] = array(); + if (!isset($_SESSION['views'][$this->view->storage->name][$display_id])) { + $_SESSION['views'][$this->view->storage->name][$display_id] = array(); } - $session = &$_SESSION['views'][$this->view->name][$display_id]; + $session = &$_SESSION['views'][$this->view->storage->name][$display_id]; $session[$this->options['group_info']['identifier']] = $input[$this->options['group_info']['identifier']]; } @@ -1334,8 +1334,8 @@ public function storeExposedInput($input, $status) { // false means that we got a setting that means to recuse ourselves, // so we should erase whatever happened to be there. - if (!$status && isset($_SESSION['views'][$this->view->name][$display_id])) { - $session = &$_SESSION['views'][$this->view->name][$display_id]; + if (!$status && isset($_SESSION['views'][$this->view->storage->name][$display_id])) { + $session = &$_SESSION['views'][$this->view->storage->name][$display_id]; if ($operator && isset($session[$this->options['expose']['operator_id']])) { unset($session[$this->options['expose']['operator_id']]); } @@ -1346,11 +1346,11 @@ public function storeExposedInput($input, $status) { } if ($status) { - if (!isset($_SESSION['views'][$this->view->name][$display_id])) { - $_SESSION['views'][$this->view->name][$display_id] = array(); + if (!isset($_SESSION['views'][$this->view->storage->name][$display_id])) { + $_SESSION['views'][$this->view->storage->name][$display_id] = array(); } - $session = &$_SESSION['views'][$this->view->name][$display_id]; + $session = &$_SESSION['views'][$this->view->storage->name][$display_id]; if ($operator && isset($input[$this->options['expose']['operator_id']])) { $session[$this->options['expose']['operator_id']] = $input[$this->options['expose']['operator_id']]; diff --git a/lib/Drupal/views/Plugin/views/pager/Full.php b/lib/Drupal/views/Plugin/views/pager/Full.php index 78f6b0954378..f99eabe6d69a 100644 --- a/lib/Drupal/views/Plugin/views/pager/Full.php +++ b/lib/Drupal/views/Plugin/views/pager/Full.php @@ -291,7 +291,7 @@ public function query() { } function render($input) { - $pager_theme = views_theme_functions('pager', $this->view, $this->view->display[$this->view->current_display]); + $pager_theme = views_theme_functions('pager', $this->view, $this->view->display_handler->display); // The 0, 1, 3, 4 index are correct. See theme_pager documentation. $tags = array( 0 => $this->options['tags']['first'], diff --git a/lib/Drupal/views/Plugin/views/pager/Mini.php b/lib/Drupal/views/Plugin/views/pager/Mini.php index 4b454b9136c2..1fb58cf4b9fd 100644 --- a/lib/Drupal/views/Plugin/views/pager/Mini.php +++ b/lib/Drupal/views/Plugin/views/pager/Mini.php @@ -32,7 +32,7 @@ public function summaryTitle() { } function render($input) { - $pager_theme = views_theme_functions('views_mini_pager', $this->view, $this->view->display[$this->view->current_display]); + $pager_theme = views_theme_functions('views_mini_pager', $this->view, $this->view->display_handler->display); return theme($pager_theme, array( 'parameters' => $input, 'element' => $this->options['id'])); } diff --git a/lib/Drupal/views/Plugin/views/query/Sql.php b/lib/Drupal/views/Plugin/views/query/Sql.php index c106be6f4ed1..894553c7c05c 100644 --- a/lib/Drupal/views/Plugin/views/query/Sql.php +++ b/lib/Drupal/views/Plugin/views/query/Sql.php @@ -1285,7 +1285,7 @@ public function query($get_count = FALSE) { $query = Database::getConnection($target, $key) ->select($this->base_table, $this->base_table, $options) ->addTag('views') - ->addTag('views_' . $this->view->name); + ->addTag('views_' . $this->view->storage->name); // Add the tags added to the view itself. foreach ($this->tags as $tag) { @@ -1516,7 +1516,7 @@ function execute(&$view) { drupal_set_message($e->getMessage(), 'error'); } else { - throw new DatabaseExceptionWrapper(format_string('Exception in @human_name[@view_name]: @message', array('@human_name' => $view->human_name, '@view_name' => $view->name, '@message' => $e->getMessage()))); + throw new DatabaseExceptionWrapper(format_string('Exception in @human_name[@view_name]: @message', array('@human_name' => $view->storage->getHumanName(), '@view_name' => $view->storage->name, '@message' => $e->getMessage()))); } } @@ -1647,7 +1647,7 @@ function load_entities(&$results) { } function add_signature(&$view) { - $view->query->add_field(NULL, "'" . $view->name . ':' . $view->current_display . "'", 'view_name'); + $view->query->add_field(NULL, "'" . $view->storage->name . ':' . $view->current_display . "'", 'view_name'); } function get_aggregation_info() { diff --git a/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php b/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php index 5eb60da96e2d..b570523c76ab 100644 --- a/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php +++ b/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php @@ -132,10 +132,10 @@ public function buildOptionsForm(&$form, &$form_state) { // TODO: check the field is the correct sort? // or let users hang themselves at this stage and check later? if ($view->type == 'Default') { - $views[t('Default Views')][$view->name] = $view->name; + $views[t('Default Views')][$view->storage->name] = $view->storage->name; } else { - $views[t('Existing Views')][$view->name] = $view->name; + $views[t('Existing Views')][$view->storage->name] = $view->storage->name; } } } @@ -173,7 +173,7 @@ function get_temporary_view() { * When the form is submitted, take sure to clear the subquery string cache. */ public function submitOptionsForm(&$form, &$form_state) { - $cid = 'views_relationship_groupwise_max:' . $this->view->name . ':' . $this->view->current_display . ':' . $this->options['id']; + $cid = 'views_relationship_groupwise_max:' . $this->view->storage->name . ':' . $this->view->current_display . ':' . $this->options['id']; cache('views_data')->delete($cid); } @@ -360,7 +360,7 @@ public function query() { } else { // Get the stored subquery SQL string. - $cid = 'views_relationship_groupwise_max:' . $this->view->name . ':' . $this->view->current_display . ':' . $this->options['id']; + $cid = 'views_relationship_groupwise_max:' . $this->view->storage->name . ':' . $this->view->current_display . ':' . $this->options['id']; $cache = cache('views_data')->get($cid); if (isset($cache->data)) { $def['left_query'] = $cache->data; diff --git a/lib/Drupal/views/Plugin/views/style/StylePluginBase.php b/lib/Drupal/views/Plugin/views/style/StylePluginBase.php index 4f94b234c36e..6f2bee647b96 100644 --- a/lib/Drupal/views/Plugin/views/style/StylePluginBase.php +++ b/lib/Drupal/views/Plugin/views/style/StylePluginBase.php @@ -438,7 +438,7 @@ function render_grouping_sets($sets, $level = 0) { $row = reset($set['rows']); // Render as a grouping set. if (is_array($row) && isset($row['group'])) { - $output .= theme(views_theme_functions('views_view_grouping', $this->view, $this->view->display[$this->view->current_display]), + $output .= theme(views_theme_functions('views_view_grouping', $this->view, $this->view->display_handler->display), array( 'view' => $this->view, 'grouping' => $this->options['grouping'][$level], diff --git a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php index 1593ced68211..add64cea14e6 100644 --- a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php +++ b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php @@ -565,9 +565,7 @@ protected function instantiate_view($form, &$form_state) { $this->addDisplays($view, $display_options, $form, $form_state); - $executable = new ViewExecutable($view); - - return $executable; + return $view->getExecutable(); } /** diff --git a/lib/Drupal/views/Tests/AnalyzeTest.php b/lib/Drupal/views/Tests/AnalyzeTest.php index a368d3953881..f5497f2191af 100644 --- a/lib/Drupal/views/Tests/AnalyzeTest.php +++ b/lib/Drupal/views/Tests/AnalyzeTest.php @@ -41,7 +41,6 @@ function testAnalyzeBasic() { $this->drupalLogin($this->admin); // Enable the frontpage view and click the analyse button. $view = views_get_view('frontpage'); - $view = $view->createDuplicate(); $this->drupalGet('admin/structure/views/view/frontpage/edit'); $this->assertLink(t('analyze view')); diff --git a/lib/Drupal/views/Tests/Field/HandlerFieldFieldTest.php b/lib/Drupal/views/Tests/Field/HandlerFieldFieldTest.php index 2003e521054f..a73806242340 100644 --- a/lib/Drupal/views/Tests/Field/HandlerFieldFieldTest.php +++ b/lib/Drupal/views/Tests/Field/HandlerFieldFieldTest.php @@ -116,16 +116,18 @@ public function _testFormatterSimpleFieldRender() { public function _testMultipleFieldRender() { $view = $this->getView(); + $field_name = $this->fields[3]['field_name']; // Test delta limit. - $view->displayHandlers['default']->options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE; - $view->displayHandlers['default']->options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3; + $view->initDisplay(); + $view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 3; $this->executeView($view); for ($i = 0; $i < 3; $i++) { - $rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']); + $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; $pure_items = array_splice($pure_items, 0, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; @@ -139,15 +141,16 @@ public function _testMultipleFieldRender() { $view->destroy(); // Test delta limit + offset - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_offset'] = 1; + $view->initDisplay(); + $view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 3; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_offset'] = 1; $this->executeView($view); for ($i = 0; $i < 3; $i++) { - $rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']); + $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; $pure_items = array_splice($pure_items, 1, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; @@ -157,16 +160,17 @@ public function _testMultipleFieldRender() { $view->destroy(); // Test delta limit + reverse. - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_offset'] = 0; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_reversed'] = TRUE; + $view->initDisplay(); + $view->displayHandlers['default']->options['fields'][$field_name]['delta_offset'] = 0; + $view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 3; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_reversed'] = TRUE; $this->executeView($view); for ($i = 0; $i < 3; $i++) { - $rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']); + $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; array_splice($pure_items, 0, -3); $pure_items = array_reverse($pure_items); foreach ($pure_items as $j => $item) { @@ -177,16 +181,17 @@ public function _testMultipleFieldRender() { $view->destroy(); // Test delta first last. - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_limit'] = 0; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_first_last'] = TRUE; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_reversed'] = FALSE; + $view->initDisplay(); + $view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 0; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_first_last'] = TRUE; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_reversed'] = FALSE; $this->executeView($view); for ($i = 0; $i < 3; $i++) { - $rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']); + $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; $items[] = $pure_items[0]['value']; $items[] = $pure_items[4]['value']; $this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.'); @@ -194,16 +199,17 @@ public function _testMultipleFieldRender() { $view->destroy(); // Test delta limit + custom seperator. - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_first_last'] = FALSE; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE; - $view->display['default']['display_options']['fields'][$this->fields[3]['field_name']]['separator'] = ':'; + $view->initDisplay(); + $view->displayHandlers['default']->options['fields'][$field_name]['delta_first_last'] = FALSE; + $view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 3; + $view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE; + $view->displayHandlers['default']->options['fields'][$field_name]['separator'] = ':'; $this->executeView($view); for ($i = 0; $i < 3; $i++) { - $rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']); + $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; $pure_items = array_splice($pure_items, 0, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; diff --git a/lib/Drupal/views/Tests/Handler/FilterCombineTest.php b/lib/Drupal/views/Tests/Handler/FilterCombineTest.php index 160fb5cdee9a..eb487a2211e6 100644 --- a/lib/Drupal/views/Tests/Handler/FilterCombineTest.php +++ b/lib/Drupal/views/Tests/Handler/FilterCombineTest.php @@ -35,7 +35,7 @@ function setUp() { protected function getBasicView() { $view = parent::getBasicView(); - $view->display['default']['display_options']['fields']['job'] = array( + $view->displayHandlers['default']->display['display_options']['fields']['job'] = array( 'id' => 'job', 'table' => 'views_test_data', 'field' => 'job', diff --git a/lib/Drupal/views/Tests/Plugin/ArgumentDefaultTest.php b/lib/Drupal/views/Tests/Plugin/ArgumentDefaultTest.php index 0c638cc9bba9..6c9e12088721 100644 --- a/lib/Drupal/views/Tests/Plugin/ArgumentDefaultTest.php +++ b/lib/Drupal/views/Tests/Plugin/ArgumentDefaultTest.php @@ -142,7 +142,7 @@ function testArgumentDefaultFixed() { */ protected function getBasicView() { $view = $this->createViewFromConfig('test_argument_default_fixed'); - $view->display['default']['display_options']['arguments']['null']['default_argument_options']['argument'] = $this->random; + $view->displayHandlers['default']->display['display_options']['arguments']['null']['default_argument_options']['argument'] = $this->random; return $view; } diff --git a/lib/Drupal/views/Tests/Plugin/CacheTest.php b/lib/Drupal/views/Tests/Plugin/CacheTest.php index 2c75f441b756..20f98348b662 100644 --- a/lib/Drupal/views/Tests/Plugin/CacheTest.php +++ b/lib/Drupal/views/Tests/Plugin/CacheTest.php @@ -38,11 +38,11 @@ protected function setUp() { protected function getBasicView() { // Create the basic view. $view = $this->createViewFromConfig('test_view'); - $view->addDisplay('default'); - $view->base_table = 'views_test_data'; + $view->storage->addDisplay('default'); + $view->storage->base_table = 'views_test_data'; // Set up the fields we need. - $display = $view->newDisplay('default', 'Master', 'default'); + $display = $view->storage->newDisplay('default', 'Master', 'default'); $display->overrideOption('fields', array( 'id' => array( 'id' => 'id', @@ -161,7 +161,7 @@ function testHeaderStorage() { // Some hook_views_pre_render in views_test_data.module adds the test css/js file. // so they should be added to the css/js storage. $view = $this->getView(); - $view->name = 'test_cache_header_storage'; + $view->storage->name = 'test_cache_header_storage'; $view->display_handler->overrideOption('cache', array( 'type' => 'time', 'output_lifespan' => '3600', @@ -185,7 +185,7 @@ function testHeaderStorage() { // Now add some css/jss before running the view. // Make sure that this css is not added when running the cached view. - $view->name = 'test_cache_header_storage_2'; + $view->storage->name = 'test_cache_header_storage_2'; $system_css_path = drupal_get_path('module', 'system') . '/system.maintenance.css'; drupal_add_css($system_css_path); diff --git a/lib/Drupal/views/Tests/Plugin/DisplayTest.php b/lib/Drupal/views/Tests/Plugin/DisplayTest.php index 425dabf514b9..e7acdf283e7a 100644 --- a/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ b/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -52,9 +52,9 @@ function testDisplayPlugin() { $view = views_get_view('frontpage'); // Add a new 'display_test' display and test it's there. - $view->addDisplay('display_test'); + $view->storage->addDisplay('display_test'); - $this->assertTrue(isset($view->display['display_test_1']), 'Added display has been assigned to "display_test_1"'); + $this->assertTrue(isset($view->storage->display['display_test_1']), 'Added display has been assigned to "display_test_1"'); // Check the the display options are like expected. $options = array( @@ -64,7 +64,7 @@ function testDisplayPlugin() { 'display_title' => 'Display test', 'position' => NULL, ); - $this->assertEqual($view->display['display_test_1'], $options); + $this->assertEqual($view->storage->display['display_test_1'], $options); $view->setDisplay('display_test_1'); diff --git a/lib/Drupal/views/Tests/Plugin/FilterTest.php b/lib/Drupal/views/Tests/Plugin/FilterTest.php index f200f06c4300..ad6ee1d0e8f0 100644 --- a/lib/Drupal/views/Tests/Plugin/FilterTest.php +++ b/lib/Drupal/views/Tests/Plugin/FilterTest.php @@ -138,7 +138,7 @@ public function testFilterQuery() { $this->executeView($view); // Check if we have all 5 results. - $this->assertEqual(count($view->result), 5, format_string('All @count results returned', array('@count' => count($view->display)))); + $this->assertEqual(count($view->result), 5, format_string('All @count results returned', array('@count' => count($view->displayHandlers)))); } } diff --git a/lib/Drupal/views/Tests/Plugin/PagerTest.php b/lib/Drupal/views/Tests/Plugin/PagerTest.php index a7d9ba7f08f2..6aa64c51c5d1 100644 --- a/lib/Drupal/views/Tests/Plugin/PagerTest.php +++ b/lib/Drupal/views/Tests/Plugin/PagerTest.php @@ -246,13 +246,6 @@ public function testNormalPager() { $this->assertEqual(count($view->result), 11); } - /** - * Tests the minipager. - */ - public function testMiniPager() { - // the functionality is the same as the normal pager, so i don't know what to test here. - } - /** * Tests rendering with NULL pager. */ diff --git a/lib/Drupal/views/Tests/UpgradeTestCase.php b/lib/Drupal/views/Tests/UpgradeTestCase.php index 6aedec1e66e3..2ee7fd235b14 100644 --- a/lib/Drupal/views/Tests/UpgradeTestCase.php +++ b/lib/Drupal/views/Tests/UpgradeTestCase.php @@ -67,7 +67,7 @@ function debugField($field) { public function testMovedTo() { // Test moving on field lavel. $view = $this->createViewFromConfig('test_views_move_to_field'); - $view->update(); + $view->storage->update(); $view->build(); // $this->assertEqual('old_field_1', $view->field['old_field_1']->options['id'], "Id shouldn't change during conversion"); @@ -78,7 +78,7 @@ public function testMovedTo() { // Test moving on handler lavel. $view = $this->createViewFromConfig('test_views_move_to_handler'); - $view->update(); + $view->storage->update(); $view->build(); // $this->assertEqual('old_field_2', $view->field['old_field_2']->options['id']); @@ -91,10 +91,10 @@ public function testMovedTo() { // Test moving on table level. $view = $this->createViewFromConfig('test_views_move_to_table'); - $view->update(); + $view->storage->update(); $view->build(); - $this->assertEqual('views_test_data', $view->base_table, 'Make sure that view->base_table gets automatically converted.'); + $this->assertEqual('views_test_data', $view->storage->base_table, 'Make sure that view->base_table gets automatically converted.'); // $this->assertEqual('id', $view->field['id']->field, 'If we move a whole table fields of this table should work, too.'); $this->assertEqual('id', $view->field['id']->realField, 'To run the query right the realField has to be set right.'); $this->assertEqual('views_test_data', $view->field['id']->table); diff --git a/lib/Drupal/views/Tests/ViewExecutableTest.php b/lib/Drupal/views/Tests/ViewExecutableTest.php index 02eb4d97cc3d..d3a80fe9dd63 100644 --- a/lib/Drupal/views/Tests/ViewExecutableTest.php +++ b/lib/Drupal/views/Tests/ViewExecutableTest.php @@ -59,18 +59,9 @@ public function testConstructing() { */ public function testProperties() { $view = $this->getView(); - $storage = $view->storage; - foreach ($this->configProperties as $property) { - $this->assertIdentical($view->{$property}, $storage->{$property}, format_string("Property '%property' is set on the stored view.", array('%property' => $property))); - } foreach ($this->executableProperties as $property) { $this->assertTrue(isset($view->{$property})); } - - // Set one storage property manually on the storage and verify that it is - // access on the executable. - $storage->human_name = $this->randomName(); - $this->assertIdentical($view->human_name, $storage->human_name); } /** diff --git a/lib/Drupal/views/Tests/ViewStorageTest.php b/lib/Drupal/views/Tests/ViewStorageTest.php index 186858cab6cb..1a150be023fb 100644 --- a/lib/Drupal/views/Tests/ViewStorageTest.php +++ b/lib/Drupal/views/Tests/ViewStorageTest.php @@ -143,7 +143,7 @@ protected function loadTests() { // Make sure that loaded default views get a uuid. $view = views_get_view('frontpage'); - $this->assertTrue($view->uuid()); + $this->assertTrue($view->storage->uuid()); } /** @@ -386,8 +386,8 @@ protected function displayMethodTests() { // Tests item related methods(). $view = $this->controller->create(array('base_table' => 'views_test_data')); - $executable = new ViewExecutable($view); $view->addDisplay('default'); + $view = $view->getExecutable(); $display_id = 'default'; $expected_items = array(); diff --git a/lib/Drupal/views/Tests/ViewTest.php b/lib/Drupal/views/Tests/ViewTest.php index ed27f4d9b3e4..ef0493cbdaac 100644 --- a/lib/Drupal/views/Tests/ViewTest.php +++ b/lib/Drupal/views/Tests/ViewTest.php @@ -116,7 +116,7 @@ public function testCreateDuplicate() { $this->assertTrue($copy instanceof ViewStorage, 'The copied object is a View.'); // Check that the original view and the copy have different uuids. - $this->assertNotIdentical($view->uuid(), $copy->uuid(), 'The copied view has a new uuid.'); + $this->assertNotIdentical($view->storage->uuid(), $copy->uuid(), 'The copied view has a new uuid.'); // Check the 'name' (id) is using the View objects default value ('') as it // gets unset. @@ -135,11 +135,11 @@ public function testCreateDuplicate() { ); foreach ($config_properties as $property) { - $this->assertIdentical($view->{$property}, $copy->{$property}, format_string('@property property is identical.', array('@property' => $property))); + $this->assertIdentical($view->storage->{$property}, $copy->{$property}, format_string('@property property is identical.', array('@property' => $property))); } // Check the displays are the same. - foreach ($view->display as $id => $display) { + foreach ($view->storage->display as $id => $display) { // assertIdentical will not work here. $this->assertEqual($display, $copy->display[$id], format_string('The @display display has been copied correctly.', array('@display' => $id))); } diff --git a/lib/Drupal/views/Tests/ViewTestBase.php b/lib/Drupal/views/Tests/ViewTestBase.php index 7c00eb3fd657..408d93923112 100644 --- a/lib/Drupal/views/Tests/ViewTestBase.php +++ b/lib/Drupal/views/Tests/ViewTestBase.php @@ -193,7 +193,7 @@ protected function getBasicPageView() { // the exposed forms cache. drupal_static_reset('views_exposed_form_cache'); - $display = $view->newDisplay('page', 'Page', 'page_1'); + $display = $view->storage->newDisplay('page', 'Page', 'page_1'); return $view; } @@ -415,7 +415,7 @@ protected function createViewFromConfig($view_name) { $data = config("views.view.$view_name")->get(); $view = entity_create('view', $data); - $view = new ViewExecutable($view); + $view = $view->getExecutable(); $view->setDisplay(); return $view; diff --git a/lib/Drupal/views/ViewExecutable.php b/lib/Drupal/views/ViewExecutable.php index 9914aecc314b..685783153ec0 100644 --- a/lib/Drupal/views/ViewExecutable.php +++ b/lib/Drupal/views/ViewExecutable.php @@ -514,55 +514,10 @@ public function __construct(ViewStorage $storage) { } /** - * Implements the magic __get() method. - * - * @todo Remove this once all calls are changed to use storage directly. - */ - public function &__get($name) { - if (property_exists($this->storage, $name)) { - return $this->storage->{$name}; - } - elseif (property_exists($this, $name)) { - return $this->{$name}; - } - } - - /** - * Implements the magic __set() method. - * - * @todo Remove this once all calls are changed to use storage directly. + * @todo. */ - public function __set($name, $value) { - if (property_exists($this, $name)) { - $this->{$name} = $value; - } - elseif (property_exists($this->storage, $name)) { - $this->storage->{$name} = $value; - } - } - - /** - * Implements the magic __call() method. - * - * @todo Remove this once all calls are changed to use storage directly. - */ - public function __call($name, $arguments) { - if (method_exists($this->storage, $name)) { - return call_user_func_array(array($this->storage, $name), $arguments); - } - } - - /** - * Perform automatic updates when loading or importing a view. - * - * Over time, some things about Views or Drupal data has changed. - * this attempts to do some automatic updates that must happen - * to ensure older views will at least try to work. - */ - public function update() { - // When views are converted automatically the base_table should be renamed - // to have a working query. - $this->storage->base_table = views_move_table($this->storage->base_table); + public function save() { + $this->storage->save(); } /** @@ -726,7 +681,7 @@ public function initDisplay($reset = FALSE) { } // Instantiate all displays - foreach (array_keys($this->display) as $id) { + foreach (array_keys($this->storage->display) as $id) { $this->displayHandlers[$id] = views_get_plugin('display', $this->storage->display[$id]['display_plugin']); if (!empty($this->displayHandlers[$id])) { // Initialize the new display handler with data. @@ -798,9 +753,9 @@ public function setDisplay($display_id = NULL) { } // Ensure the requested display exists. - if (empty($this->display[$display_id])) { + if (empty($this->displayHandlers[$display_id])) { $display_id = 'default'; - if (empty($this->display[$display_id])) { + if (empty($this->displayHandlers[$display_id])) { debug('set_display() called with invalid display ID @display.', array('@display' => $display_id)); return FALSE; } @@ -852,7 +807,7 @@ public function initStyle() { */ public function initHandlers() { if (empty($this->inited)) { - foreach (ViewExecutable::viewsHandlerTypes() as $key => $info) { + foreach ($this::viewsHandlerTypes() as $key => $info) { $this->_initHandler($key, $info); } $this->inited = TRUE; @@ -916,7 +871,7 @@ public function getBaseTables() { * Run the preQuery() on all active handlers. */ protected function _preQuery() { - foreach (ViewExecutable::viewsHandlerTypes() as $key => $info) { + foreach ($this::viewsHandlerTypes() as $key => $info) { $handlers = &$this->$key; $position = 0; foreach ($handlers as $id => $handler) { @@ -931,7 +886,7 @@ protected function _preQuery() { * Run the postExecute() on all active handlers. */ protected function _postExecute() { - foreach (ViewExecutable::viewsHandlerTypes() as $key => $info) { + foreach ($this::viewsHandlerTypes() as $key => $info) { $handlers = &$this->$key; foreach ($handlers as $id => $handler) { $handlers[$id]->postExecute($this->result); @@ -1087,7 +1042,7 @@ public function initQuery() { // Create and initialize the query object. $views_data = views_fetch_data($this->storage->base_table); - $this->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : ''; + $this->storage->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : ''; if (!empty($views_data['table']['base']['database'])) { $this->base_database = $views_data['table']['base']['database']; } @@ -1103,7 +1058,7 @@ public function initQuery() { return FALSE; } - $this->query->init($this->storage->base_table, $this->base_field, $query_options['options']); + $this->query->init($this->storage->base_table, $this->storage->base_field, $query_options['options']); return TRUE; } @@ -1583,7 +1538,7 @@ public function preExecute($args = array()) { } // Allow hook_views_pre_view() to set the dom_id, then ensure it is set. - $this->dom_id = !empty($this->dom_id) ? $this->dom_id : md5($this->name . REQUEST_TIME . rand()); + $this->dom_id = !empty($this->dom_id) ? $this->dom_id : md5($this->storage->name . REQUEST_TIME . rand()); // Allow the display handler to set up for execution $this->display_handler->preExecute(); @@ -1617,8 +1572,8 @@ public function attachDisplays() { $this->is_attachment = TRUE; // Give other displays an opportunity to attach to the view. - foreach ($this->display as $id => $display) { - if (!empty($this->display[$id])) { + foreach ($this->displayHandlers as $id => $display) { + if (!empty($this->displayHandlers[$id])) { $this->displayHandlers[$id]->attachTo($this->current_display); } } @@ -1949,7 +1904,7 @@ public function endQueryCapture() { * data, ID, and UUID. */ public function createDuplicate() { - $data = config('views.view.' . $this->id())->get(); + $data = config('views.view.' . $this->storage->id())->get(); // Reset the name and UUID. unset($data['name']); @@ -1975,11 +1930,11 @@ public function createDuplicate() { public function cloneView() { $clone = clone $this->storage; - $keys = array('current_display', 'display_handler', 'displayHandlers', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'exposed_widgets', 'many_to_one_tables', 'feed_icon'); + $keys = array('executable', 'current_display', 'display_handler', 'displayHandlers', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'exposed_widgets', 'many_to_one_tables', 'feed_icon'); foreach ($keys as $key) { unset($clone->$key); } - $clone = new ViewExecutable($clone); + $clone = $clone->getExecutable(); $clone->built = $clone->executed = FALSE; $clone->build_info = array(); $clone->attachment_before = ''; @@ -2001,7 +1956,7 @@ public function destroy() { } } - foreach (ViewExecutable::viewsHandlerTypes() as $type => $info) { + foreach ($this::viewsHandlerTypes() as $type => $info) { if (isset($this->$type)) { $handlers = &$this->$type; foreach ($handlers as $id => $item) { @@ -2182,4 +2137,219 @@ public static function getPluginTypes() { ); } + /** + * Adds an instance of a handler to the view. + * + * Items may be fields, filters, sort criteria, or arguments. + * + * @param string $display_id + * The machine name of the display. + * @param string $type + * The type of handler being added. + * @param string $table + * The name of the table this handler is from. + * @param string $field + * The name of the field this handler is from. + * @param array $options + * (optional) Extra options for this instance. Defaults to an empty array. + * @param string $id + * (optional) A unique ID for this handler instance. Defaults to NULL, in + * which case one will be generated. + * + * @return string + * The unique ID for this handler instance. + */ + public function addItem($display_id, $type, $table, $field, $options = array(), $id = NULL) { + $types = $this::viewsHandlerTypes(); + $this->setDisplay($display_id); + + $fields = $this->displayHandlers[$display_id]->getOption($types[$type]['plural']); + + if (empty($id)) { + $id = $this->generateItemId($field, $fields); + } + + // If the desired type is not found, use the original value directly. + $handler_type = !empty($types[$type]['type']) ? $types[$type]['type'] : $type; + + // @todo This variable is never used. + $handler = views_get_handler($table, $field, $handler_type); + + $fields[$id] = array( + 'id' => $id, + 'table' => $table, + 'field' => $field, + ) + $options; + + $this->displayHandlers[$display_id]->setOption($types[$type]['plural'], $fields); + + return $id; + } + + /** + * Generates a unique ID for an handler instance. + * + * These handler instances are typically fields, filters, sort criteria, or + * arguments. + * + * @param string $requested_id + * The requested ID for the handler instance. + * @param array $existing_items + * An array of existing handler instancess, keyed by their IDs. + * + * @return string + * A unique ID. This will be equal to $requested_id if no handler instance + * with that ID already exists. Otherwise, it will be appended with an + * integer to make it unique, e.g., "{$requested_id}_1", + * "{$requested_id}_2", etc. + */ + public static function generateItemId($requested_id, $existing_items) { + $count = 0; + $id = $requested_id; + while (!empty($existing_items[$id])) { + $id = $requested_id . '_' . ++$count; + } + return $id; + } + + /** + * Gets an array of handler instances for the current display. + * + * @param string $type + * The type of handlers to retrieve. + * @param string $display_id + * (optional) A specific display machine name to use. If NULL, the current + * display will be used. + * + * @return array + * An array of handler instances of a given type for this display. + */ + public function getItems($type, $display_id = NULL) { + $this->setDisplay($display_id); + + if (!isset($display_id)) { + $display_id = $this->current_display; + } + + // Get info about the types so we can get the right data. + $types = $this::viewsHandlerTypes(); + return $this->displayHandlers[$display_id]->getOption($types[$type]['plural']); + } + + /** + * Gets the configuration of a handler instance on a given display. + * + * @param string $display_id + * The machine name of the display. + * @param string $type + * The type of handler to retrieve. + * @param string $id + * The ID of the handler to retrieve. + * + * @return array|null + * Either the handler instance's configuration, or NULL if the handler is + * not used on the display. + */ + public function getItem($display_id, $type, $id) { + // Get info about the types so we can get the right data. + $types = $this::viewsHandlerTypes(); + // Initialize the display + $this->setDisplay($display_id); + + // Get the existing configuration + $fields = $this->displayHandlers[$display_id]->getOption($types[$type]['plural']); + + return isset($fields[$id]) ? $fields[$id] : NULL; + } + + /** + * Sets the configuration of a handler instance on a given display. + * + * @param string $display_id + * The machine name of the display. + * @param string $type + * The type of handler being set. + * @param string $id + * The ID of the handler being set. + * @param array|null $item + * An array of configuration for a handler, or NULL to remove this instance. + * + * @see set_item_option() + */ + public function setItem($display_id, $type, $id, $item) { + // Get info about the types so we can get the right data. + $types = $this::viewsHandlerTypes(); + // Initialize the display. + $this->setDisplay($display_id); + + // Get the existing configuration. + $fields = $this->displayHandlers[$display_id]->getOption($types[$type]['plural']); + if (isset($item)) { + $fields[$id] = $item; + } + else { + unset($fields[$id]); + } + + // Store. + $this->displayHandlers[$display_id]->setOption($types[$type]['plural'], $fields); + } + + /** + * Sets an option on a handler instance. + * + * Use this only if you have just 1 or 2 options to set; if you have many, + * consider getting the handler instance, adding the options and using + * set_item() directly. + * + * @param string $display_id + * The machine name of the display. + * @param string $type + * The type of handler being set. + * @param string $id + * The ID of the handler being set. + * @param string $option + * The configuration key for the value being set. + * @param mixed $value + * The value being set. + * + * @see set_item() + */ + public function setItemOption($display_id, $type, $id, $option, $value) { + $item = $this->getItem($display_id, $type, $id); + $item[$option] = $value; + $this->setItem($display_id, $type, $id, $item); + } + + /** + * Creates and stores a new display. + * + * @param string $id + * The ID for the display being added. + * + * @return Drupal\views\Plugin\views\display\DisplayPluginBase + * A reference to the new handler object. + */ + public function &newDisplay($id) { + // Create a handler. + $this->displayHandlers[$id] = views_get_plugin('display', $this->storage->display[$id]['display_plugin']); + if (empty($this->displayHandlers[$id])) { + // provide a 'default' handler as an emergency. This won't work well but + // it will keep things from crashing. + $this->displayHandlers[$id] = views_get_plugin('display', 'default'); + } + + if (!empty($this->displayHandlers[$id])) { + // Initialize the new display handler with data. + $this->displayHandlers[$id]->init($this, $this->storage->display[$id]); + // If this is NOT the default display handler, let it know which is + if ($id != 'default') { + // @todo is the '&' still required in php5? + $this->displayHandlers[$id]->default_display = &$this->displayHandlers['default']; + } + } + + return $this->displayHandlers[$id]; + } + } diff --git a/lib/Drupal/views/ViewStorage.php b/lib/Drupal/views/ViewStorage.php index 512174f3a734..70151fa9224b 100644 --- a/lib/Drupal/views/ViewStorage.php +++ b/lib/Drupal/views/ViewStorage.php @@ -14,15 +14,6 @@ */ class ViewStorage extends ConfigEntityBase implements ViewStorageInterface { - /** - * Provide direct access to the UUID. - * - * @todo Change usage of this to the uuid() method. - * - * @var string - */ - public $uuid; - /** * The name of the base table this view will use. * @@ -136,59 +127,31 @@ public function setExecutable(ViewExecutable $executable) { } /** - * Initializes the display. + * Retrieves the executable version of this view. * - * @todo Inspect calls to this and attempt to clean up. - * - * @param bool $reset - * If the display should be reset. Defaults to FALSE. - * - * @see Drupal\views\ViewExecutable::initDisplay() + * @return Drupal\views\ViewExecutable + * The executable version of this view. */ - public function initDisplay($reset = FALSE) { + public function getExecutable() { if (!isset($this->executable)) { $this->setExecutable(new ViewExecutable($this)); } - $this->executable->initDisplay($reset); + return $this->executable; } /** - * Implements the magic __call() method. + * Initializes the display. * - * @todo Remove this once all calls are changed to use executable directly. - */ - public function __call($name, $arguments) { - if (method_exists($this->executable, $name)) { - return call_user_func_array(array($this->executable, $name), $arguments); - } - } - - /** - * Implements the magic __get() method. + * @todo Inspect calls to this and attempt to clean up. * - * @todo Remove this once all calls are changed to use executable directly. - */ - public function &__get($name) { - if (property_exists($this->executable, $name)) { - return $this->executable->{$name}; - } - if (property_exists($this, $name)) { - return $this->{$name}; - } - } - - /** - * Implements the magic __set() method. + * @param bool $reset + * If the display should be reset. Defaults to FALSE. * - * @todo Remove this once all calls are changed to use executable directly. + * @see Drupal\views\ViewExecutable::initDisplay() */ - public function __set($name, $value) { - if (property_exists($this, $name)) { - $this->{$name} = $value; - } - elseif (property_exists($this->executable, $name)) { - $this->executable->{$name} = $value; - } + public function initDisplay($reset = FALSE) { + $this->getExecutable(); + $this->executable->initDisplay($reset); } /** @@ -243,6 +206,19 @@ public function getHumanName() { return $human_name; } + /** + * Perform automatic updates when loading or importing a view. + * + * Over time, some things about Views or Drupal data has changed. + * this attempts to do some automatic updates that must happen + * to ensure older views will at least try to work. + */ + public function update() { + // When views are converted automatically the base_table should be renamed + // to have a working query. + $this->base_table = views_move_table($this->base_table); + } + /** * Adds a new display handler to the view, automatically creating an ID. * @@ -330,32 +306,6 @@ protected function generateDisplayId($plugin_id) { return $id; } - /** - * Generates a unique ID for an handler instance. - * - * These handler instances are typically fields, filters, sort criteria, or - * arguments. - * - * @param string $requested_id - * The requested ID for the handler instance. - * @param array $existing_items - * An array of existing handler instancess, keyed by their IDs. - * - * @return string - * A unique ID. This will be equal to $requested_id if no handler instance - * with that ID already exists. Otherwise, it will be appended with an - * integer to make it unique, e.g., "{$requested_id}_1", - * "{$requested_id}_2", etc. - */ - public static function generateItemId($requested_id, $existing_items) { - $count = 0; - $id = $requested_id; - while (!empty($existing_items[$id])) { - $id = $requested_id . '_' . ++$count; - } - return $id; - } - /** * Creates a new display and a display handler for it. * @@ -373,26 +323,8 @@ public static function generateItemId($requested_id, $existing_items) { */ public function &newDisplay($plugin_id = 'page', $title = NULL, $id = NULL) { $id = $this->addDisplay($plugin_id, $title, $id); - - // Create a handler. - $this->executable->displayHandlers[$id] = views_get_plugin('display', $this->display[$id]['display_plugin']); - if (empty($this->executable->displayHandlers[$id])) { - // provide a 'default' handler as an emergency. This won't work well but - // it will keep things from crashing. - $this->executable->displayHandlers[$id] = views_get_plugin('display', 'default'); - } - - if (!empty($this->executable->displayHandlers[$id])) { - // Initialize the new display handler with data. - $this->executable->displayHandlers[$id]->init($this, $this->display[$id]); - // If this is NOT the default display handler, let it know which is - if ($id != 'default') { - // @todo is the '&' still required in php5? - $this->executable->displayHandlers[$id]->default_display = &$this->executable->displayHandlers['default']; - } - } - - return $this->executable->displayHandlers[$id]; + $this->getExecutable(); + return $this->executable->newDisplay($id); } /** @@ -443,162 +375,4 @@ public function getPaths() { return array_unique($all_paths); } - /** - * Adds an instance of a handler to the view. - * - * Items may be fields, filters, sort criteria, or arguments. - * - * @param string $display_id - * The machine name of the display. - * @param string $type - * The type of handler being added. - * @param string $table - * The name of the table this handler is from. - * @param string $field - * The name of the field this handler is from. - * @param array $options - * (optional) Extra options for this instance. Defaults to an empty array. - * @param string $id - * (optional) A unique ID for this handler instance. Defaults to NULL, in - * which case one will be generated. - * - * @return string - * The unique ID for this handler instance. - */ - public function addItem($display_id, $type, $table, $field, $options = array(), $id = NULL) { - $types = ViewExecutable::viewsHandlerTypes(); - $this->setDisplay($display_id); - - $fields = $this->executable->displayHandlers[$display_id]->getOption($types[$type]['plural']); - - if (empty($id)) { - $id = $this->generateItemId($field, $fields); - } - - // If the desired type is not found, use the original value directly. - $handler_type = !empty($types[$type]['type']) ? $types[$type]['type'] : $type; - - // @todo This variable is never used. - $handler = views_get_handler($table, $field, $handler_type); - - $fields[$id] = array( - 'id' => $id, - 'table' => $table, - 'field' => $field, - ) + $options; - - $this->executable->displayHandlers[$display_id]->setOption($types[$type]['plural'], $fields); - - return $id; - } - - /** - * Gets an array of handler instances for the current display. - * - * @param string $type - * The type of handlers to retrieve. - * @param string $display_id - * (optional) A specific display machine name to use. If NULL, the current - * display will be used. - * - * @return array - * An array of handler instances of a given type for this display. - */ - public function getItems($type, $display_id = NULL) { - $this->setDisplay($display_id); - - if (!isset($display_id)) { - $display_id = $this->current_display; - } - - // Get info about the types so we can get the right data. - $types = ViewExecutable::viewsHandlerTypes(); - return $this->executable->displayHandlers[$display_id]->getOption($types[$type]['plural']); - } - - /** - * Gets the configuration of a handler instance on a given display. - * - * @param string $display_id - * The machine name of the display. - * @param string $type - * The type of handler to retrieve. - * @param string $id - * The ID of the handler to retrieve. - * - * @return array|null - * Either the handler instance's configuration, or NULL if the handler is - * not used on the display. - */ - public function getItem($display_id, $type, $id) { - // Get info about the types so we can get the right data. - $types = ViewExecutable::viewsHandlerTypes(); - // Initialize the display - $this->setDisplay($display_id); - - // Get the existing configuration - $fields = $this->executable->displayHandlers[$display_id]->getOption($types[$type]['plural']); - - return isset($fields[$id]) ? $fields[$id] : NULL; - } - - /** - * Sets the configuration of a handler instance on a given display. - * - * @param string $display_id - * The machine name of the display. - * @param string $type - * The type of handler being set. - * @param string $id - * The ID of the handler being set. - * @param array|null $item - * An array of configuration for a handler, or NULL to remove this instance. - * - * @see set_item_option() - */ - public function setItem($display_id, $type, $id, $item) { - // Get info about the types so we can get the right data. - $types = ViewExecutable::viewsHandlerTypes(); - // Initialize the display. - $this->setDisplay($display_id); - - // Get the existing configuration. - $fields = $this->executable->displayHandlers[$display_id]->getOption($types[$type]['plural']); - if (isset($item)) { - $fields[$id] = $item; - } - else { - unset($fields[$id]); - } - - // Store. - $this->executable->displayHandlers[$display_id]->setOption($types[$type]['plural'], $fields); - } - - /** - * Sets an option on a handler instance. - * - * Use this only if you have just 1 or 2 options to set; if you have many, - * consider getting the handler instance, adding the options and using - * set_item() directly. - * - * @param string $display_id - * The machine name of the display. - * @param string $type - * The type of handler being set. - * @param string $id - * The ID of the handler being set. - * @param string $option - * The configuration key for the value being set. - * @param mixed $value - * The value being set. - * - * @see set_item() - */ - public function setItemOption($display_id, $type, $id, $option, $value) { - $item = $this->getItem($display_id, $type, $id); - $item[$option] = $value; - $this->setItem($display_id, $type, $id, $item); - } - } diff --git a/lib/Views/block/Plugin/views/display/Block.php b/lib/Views/block/Plugin/views/display/Block.php index 69f25b67ba12..a1d205aff4ce 100644 --- a/lib/Views/block/Plugin/views/display/Block.php +++ b/lib/Views/block/Plugin/views/display/Block.php @@ -52,15 +52,15 @@ protected function defineOptions() { * stuff with it. */ public function executeHookBlockList($delta = 0, $edit = array()) { - $delta = $this->view->name . '-' . $this->display['id']; + $delta = $this->view->storage->name . '-' . $this->display['id']; $desc = $this->getOption('block_description'); if (empty($desc)) { if ($this->display['display_title'] == $this->definition['title']) { - $desc = t('View: !view', array('!view' => $this->view->getHumanName())); + $desc = t('View: !view', array('!view' => $this->view->storage->getHumanName())); } else { - $desc = t('View: !view: !display', array('!view' => $this->view->getHumanName(), '!display' => $this->display['display_title'])); + $desc = t('View: !view: !display', array('!view' => $this->view->storage->getHumanName(), '!display' => $this->display['display_title'])); } } return array( @@ -193,14 +193,14 @@ public function submitOptionsForm(&$form, &$form_state) { parent::submitOptionsForm($form, $form_state); switch ($form_state['section']) { case 'display_id': - $this->updateBlockBid($form_state['view']->name, $this->display['id'], $this->display['new_id']); + $this->updateBlockBid($form_state['view']->storage->name, $this->display['id'], $this->display['new_id']); break; case 'block_description': $this->setOption('block_description', $form_state['values']['block_description']); break; case 'block_caching': $this->setOption('block_caching', $form_state['values']['block_caching']); - $this->saveBlockCache($form_state['view']->name . '-'. $form_state['display_id'], $form_state['values']['block_caching']); + $this->saveBlockCache($form_state['view']->storage->name . '-'. $form_state['display_id'], $form_state['values']['block_caching']); break; } } diff --git a/lib/Views/field/Plugin/views/field/Field.php b/lib/Views/field/Plugin/views/field/Field.php index 5239f2f94516..21307c36c510 100644 --- a/lib/Views/field/Plugin/views/field/Field.php +++ b/lib/Views/field/Plugin/views/field/Field.php @@ -114,7 +114,7 @@ public function access() { function get_base_table() { if (!isset($this->base_table)) { // This base_table is coming from the entity not the field. - $this->base_table = $this->view->base_table; + $this->base_table = $this->view->storage->base_table; // If the current field is under a relationship you can't be sure that the // base table of the view is the base table of the current field. diff --git a/lib/Views/node/Plugin/views/argument/CreatedDay.php b/lib/Views/node/Plugin/views/argument/CreatedDay.php index 2d2b7cc884c8..f354d7db087c 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedDay.php +++ b/lib/Views/node/Plugin/views/argument/CreatedDay.php @@ -9,27 +9,25 @@ use Drupal\Core\Annotation\Plugin; use Drupal\views\Plugin\views\argument\Date; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Argument handler for a day (DD) * * @Plugin( * id = "node_created_day", + * arg_format = "d", + * format = "j", * module = "node" * ) */ class CreatedDay extends Date { /** - * Constructs a CreatedDay object. + * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { - parent::__construct($configuration, $plugin_id, $discovery); - + function get_formula() { $this->formula = views_date_sql_extract('DAY', "***table***.$this->realField"); - $this->format = 'j'; - $this->arg_format = 'd'; + return parent::get_formula(); } /** @@ -38,7 +36,7 @@ public function __construct(array $configuration, $plugin_id, DiscoveryInterface function summary_name($data) { $day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT); // strtotime respects server timezone, so we need to set the time fixed as utc time - return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC'); + return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC'); } /** @@ -46,7 +44,7 @@ function summary_name($data) { */ function title() { $day = str_pad($this->argument, 2, '0', STR_PAD_LEFT); - return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC'); + return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC'); } function summary_argument($data) { diff --git a/lib/Views/node/Plugin/views/argument/CreatedFullDate.php b/lib/Views/node/Plugin/views/argument/CreatedFullDate.php index 934b67ea9b9b..ebb5ff69224d 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedFullDate.php +++ b/lib/Views/node/Plugin/views/argument/CreatedFullDate.php @@ -9,27 +9,25 @@ use Drupal\Core\Annotation\Plugin; use Drupal\views\Plugin\views\argument\Date; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Argument handler for a full date (CCYYMMDD) * * @Plugin( * id = "node_created_fulldate", + * arg_format = "Ymd", + * format = "F j, Y", * module = "node" * ) */ class CreatedFullDate extends Date { /** - * Constructs a CreatedFullDate object. + * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { - parent::__construct($configuration, $plugin_id, $discovery); - - $this->format = 'F j, Y'; - $this->arg_format = 'Ymd'; - $this->formula = views_date_sql_format($this->arg_format, "***table***.$this->realField"); + function get_formula() { + $this->formula = views_date_sql_format($this->definition['arg_format'], "***table***.$this->realField"); + return parent::get_formula(); } /** @@ -37,14 +35,14 @@ public function __construct(array $configuration, $plugin_id, DiscoveryInterface */ function summary_name($data) { $created = $data->{$this->name_alias}; - return format_date(strtotime($created . " 00:00:00 UTC"), 'custom', $this->format, 'UTC'); + return format_date(strtotime($created . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC'); } /** * Provide a link to the next level of the view */ function title() { - return format_date(strtotime($this->argument . " 00:00:00 UTC"), 'custom', $this->format, 'UTC'); + return format_date(strtotime($this->argument . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC'); } } diff --git a/lib/Views/node/Plugin/views/argument/CreatedMonth.php b/lib/Views/node/Plugin/views/argument/CreatedMonth.php index ed51d2080747..2278f40b532e 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedMonth.php +++ b/lib/Views/node/Plugin/views/argument/CreatedMonth.php @@ -9,27 +9,25 @@ use Drupal\Core\Annotation\Plugin; use Drupal\views\Plugin\views\argument\Date; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Argument handler for a month (MM) * * @Plugin( * id = "node_created_month", + * arg_format = "m", + * format = "F", * module = "node" * ) */ class CreatedMonth extends Date { /** - * Constructs a CreatedMonth object. + * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { - parent::__construct($configuration, $plugin_id, $discovery); - + function get_formula() { $this->formula = views_date_sql_extract('MONTH', "***table***.$this->realField"); - $this->format = 'F'; - $this->arg_format = 'm'; + return parent::get_formula(); } /** @@ -37,7 +35,7 @@ public function __construct(array $configuration, $plugin_id, DiscoveryInterface */ function summary_name($data) { $month = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT); - return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC" ), 'custom', $this->format, 'UTC'); + return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC" ), 'custom', $this->definition['format'], 'UTC'); } /** @@ -45,7 +43,7 @@ function summary_name($data) { */ function title() { $month = str_pad($this->argument, 2, '0', STR_PAD_LEFT); - return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC'); + return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC'); } function summary_argument($data) { diff --git a/lib/Views/node/Plugin/views/argument/CreatedWeek.php b/lib/Views/node/Plugin/views/argument/CreatedWeek.php index 9e5475848e8b..10723ff2edf5 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedWeek.php +++ b/lib/Views/node/Plugin/views/argument/CreatedWeek.php @@ -9,26 +9,24 @@ use Drupal\Core\Annotation\Plugin; use Drupal\views\Plugin\views\argument\Date; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Argument handler for a week. * * @Plugin( * id = "node_created_week", + * arg_format = "w", * module = "node" * ) */ class CreatedWeek extends Date { /** - * Constructs a CreatedWeek object. + * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { - parent::__construct($configuration, $plugin_id, $discovery); - - $this->arg_format = 'w'; + function get_formula() { $this->formula = views_date_sql_extract('WEEK', "***table***.$this->realField"); + return parent::get_formula(); } /** diff --git a/lib/Views/node/Plugin/views/argument/CreatedYear.php b/lib/Views/node/Plugin/views/argument/CreatedYear.php index 55d4cf779054..6250b612dd2b 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedYear.php +++ b/lib/Views/node/Plugin/views/argument/CreatedYear.php @@ -9,26 +9,24 @@ use Drupal\Core\Annotation\Plugin; use Drupal\views\Plugin\views\argument\Date; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Argument handler for a year (CCYY) * * @Plugin( * id = "node_created_year", + * arg_format = "Y", * module = "node" * ) */ class CreatedYear extends Date { /** - * Constructs a CreatedYear object. + * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { - parent::__construct($configuration, $plugin_id, $discovery); - - $this->arg_format = 'Y'; + function get_formula() { $this->formula = views_date_sql_extract('YEAR', "***table***.$this->realField"); + return parent::get_formula(); } } diff --git a/lib/Views/node/Plugin/views/argument/CreatedYearMonth.php b/lib/Views/node/Plugin/views/argument/CreatedYearMonth.php index 758f3d78b29b..090ed8b6ca4e 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedYearMonth.php +++ b/lib/Views/node/Plugin/views/argument/CreatedYearMonth.php @@ -9,27 +9,25 @@ use Drupal\Core\Annotation\Plugin; use Drupal\views\Plugin\views\argument\Date; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Argument handler for a year plus month (CCYYMM) * * @Plugin( * id = "node_created_year_month", + * format = "F Y", + * arg_format = "Ym", * module = "node" * ) */ class CreatedYearMonth extends Date { /** - * Constructs a CreatedYearMonth object. + * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { - parent::__construct($configuration, $plugin_id, $discovery); - - $this->format = 'F Y'; - $this->arg_format = 'Ym'; - $this->formula = views_date_sql_format($this->arg_format, "***table***.$this->realField"); + function get_formula() { + $this->formula = views_date_sql_format($this->definition['arg_format'], "***table***.$this->realField"); + return parent::get_formula(); } /** @@ -37,14 +35,14 @@ public function __construct(array $configuration, $plugin_id, DiscoveryInterface */ function summary_name($data) { $created = $data->{$this->name_alias}; - return format_date(strtotime($created . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC'); + return format_date(strtotime($created . "15" . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC'); } /** * Provide a link to the next level of the view */ function title() { - return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC'); + return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC'); } } diff --git a/tests/views_test_data/views_test_data.module b/tests/views_test_data/views_test_data.module index 62a67df1d33d..9f94f9a09de0 100644 --- a/tests/views_test_data/views_test_data.module +++ b/tests/views_test_data/views_test_data.module @@ -48,7 +48,7 @@ function views_test_data_test_dynamic_access_callback($access, $argument1, $argu * Implements hook_views_pre_render(). */ function views_test_data_views_pre_render(&$view) { - if ($view->name == 'test_cache_header_storage') { + if ($view->storage->name == 'test_cache_header_storage') { drupal_add_js(drupal_get_path('module', 'views_test_data') . '/views_cache.test.js'); drupal_add_css(drupal_get_path('module', 'views_test_data') . '/views_cache.test.css'); $view->build_info['pre_render_called'] = TRUE; @@ -59,7 +59,7 @@ function views_test_data_views_pre_render(&$view) { * Implements hook_views_post_build(). */ function views_test_data_views_post_build(ViewExecutable &$view) { - if ($view->name == 'test_page_display') { + if ($view->storage->name == 'test_page_display') { if ($view->current_display == 'page_1') { $view->build_info['denied'] = TRUE; } diff --git a/theme/theme.inc b/theme/theme.inc index 0a42b9ea75e0..41644ae6389a 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -21,19 +21,19 @@ function _views_theme_functions($hook, $view, $display = NULL) { $themes = array(); if ($display) { - $themes[] = $hook . '__' . $view->name . '__' . $display['id']; + $themes[] = $hook . '__' . $view->storage->name . '__' . $display['id']; $themes[] = $hook . '__' . $display['id']; // Add theme suggestions for each single tag. - foreach (drupal_explode_tags($view->tag) as $tag) { + foreach (drupal_explode_tags($view->storage->tag) as $tag) { $themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($tag)); } if ($display['id'] != $display['display_plugin']) { - $themes[] = $hook . '__' . $view->name . '__' . $display['display_plugin']; + $themes[] = $hook . '__' . $view->storage->name . '__' . $display['display_plugin']; $themes[] = $hook . '__' . $display['display_plugin']; } } - $themes[] = $hook . '__' . $view->name; + $themes[] = $hook . '__' . $view->storage->name; $themes[] = $hook; return $themes; } @@ -48,8 +48,8 @@ function template_preprocess_views_view(&$vars) { $vars['rows'] = (!empty($view->result) || $view->style_plugin->even_empty()) ? $view->style_plugin->render($view->result) : ''; - $vars['css_name'] = drupal_clean_css_identifier($view->name); - $vars['name'] = $view->name; + $vars['css_name'] = drupal_clean_css_identifier($view->storage->name); + $vars['name'] = $view->storage->name; $vars['display_id'] = $view->current_display; // Basic classes @@ -124,7 +124,7 @@ function template_preprocess_views_view(&$vars) { 'ajax_path' => url('views/ajax'), 'ajaxViews' => array( 'views_dom_id:' . $vars['dom_id'] => array( - 'view_name' => $view->name, + 'view_name' => $view->storage->name, 'view_display_id' => $view->current_display, 'view_args' => check_plain(implode('/', $view->args)), 'view_path' => check_plain(current_path()), @@ -866,7 +866,7 @@ function template_preprocess_views_view_rss(&$vars) { // Figure out which display which has a path we're using for this feed. If there isn't // one, use the global $base_url $link_display_id = $view->display_handler->getLinkDisplay(); - if ($link_display_id && !empty($view->display[$link_display_id])) { + if ($link_display_id && !empty($view->displayHandlers[$link_display_id])) { $path = $view->displayHandlers[$link_display_id]->getPath(); } diff --git a/theme/views-ui-edit-view.tpl.php b/theme/views-ui-edit-view.tpl.php index 5c3732ca5a45..566b8a42a879 100644 --- a/theme/views-ui-edit-view.tpl.php +++ b/theme/views-ui-edit-view.tpl.php @@ -21,7 +21,7 @@ <?php print $quick_links ?> </div> <?php print t('View %name, displaying items of type <strong>@base</strong>.', - array('%name' => $view->name, '@base' => $base_table)); ?> + array('%name' => $view->storage->name, '@base' => $base_table)); ?> </div> <?php print $tabs; ?> diff --git a/views.module b/views.module index 7cd7ae65a94c..e1823740e13b 100644 --- a/views.module +++ b/views.module @@ -131,7 +131,7 @@ function views_forms($form_id, $args) { function views_form_id($view) { $parts = array( 'views_form', - $view->name, + $view->storage->name, $view->current_display, ); @@ -373,7 +373,7 @@ function views_plugin_list() { } // Add this view to the list for this plugin. - $plugins[$key]['views'][$view->name] = $view->name; + $plugins[$key]['views'][$view->storage->name] = $view->storage->name; } } } @@ -390,11 +390,11 @@ function views_plugin_list() { */ function views_preprocess_node(&$vars) { // The 'view' attribute of the node is added in views_preprocess_node() - if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) { + if (!empty($vars['node']->view) && !empty($vars['node']->view->storage->name)) { $vars['view'] = $vars['node']->view; - $vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->name; + $vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->storage->name; if (!empty($vars['node']->view->current_display)) { - $vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->name . '__' . $vars['node']->view->current_display; + $vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->storage->name . '__' . $vars['node']->view->current_display; // If a node is being rendered in a view, and the view does not have a path, // prevent drupal from accidentally setting the $page variable: @@ -416,11 +416,11 @@ function views_preprocess_node(&$vars) { */ function views_preprocess_comment(&$vars) { // The 'view' attribute of the node is added in template_preprocess_views_view_row_comment() - if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) { + if (!empty($vars['node']->view) && !empty($vars['node']->view->storage->name)) { $vars['view'] = &$vars['node']->view; - $vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->name; + $vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->storage->name; if (!empty($vars['node']->view->current_display)) { - $vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->name . '__' . $vars['node']->view->current_display; + $vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->storage->name . '__' . $vars['node']->view->current_display; } } } @@ -699,7 +699,7 @@ function views_block_info() { } $view->initDisplay(); - foreach ($view->displayHandlers as $display) { + foreach ($view->executable->displayHandlers as $display) { if (isset($display) && !empty($display->definition['uses_hook_block'])) { $result = $display->executeHookBlockList(); @@ -902,7 +902,7 @@ function views_add_contextual_links(&$render_element, $location, $view, $display // Also do not do anything if the display plugin has not defined any // contextual links that are intended to be displayed in the requested // location. - $plugin = views_get_plugin_definition('display', $view->display[$display_id]['display_plugin']); + $plugin = views_get_plugin_definition('display', $view->displayHandlers[$display_id]->display['display_plugin']); // If contextual_links_locations are not set, provide a sane default. (To // avoid displaying any contextual links at all, a display plugin can still // set 'contextual_links_locations' to, e.g., {""}.) @@ -945,7 +945,7 @@ function views_add_contextual_links(&$render_element, $location, $view, $display $render_element['#views_contextual_links_info'][$module] = array( 'location' => $location, 'view' => $view, - 'view_name' => $view->name, + 'view_name' => $view->storage->name, 'view_display_id' => $display_id, ); } @@ -1542,13 +1542,12 @@ function views_get_applicable_views($type) { $views = views_get_all_views(); foreach ($views as $view) { - $view = new ViewExecutable($view); // Skip disabled views. - if (!empty($view->storage->disabled)) { + if (!empty($view->disabled)) { continue; } - if (empty($view->storage->display)) { + if (empty($view->display)) { // Skip this view as it is broken. continue; } @@ -1558,9 +1557,10 @@ function views_get_applicable_views($type) { foreach (array_keys($view->display) as $id) { $plugin = views_get_plugin_definition('display', $view->display[$id]['display_plugin']); if (!empty($plugin[$type])) { + $executable = $view->getExecutable(); // This view uses_hook_menu. Clone it so that different handlers // don't trip over each other, and add it to the list. - $v = $view->cloneView(); + $v = $executable->cloneView(); if ($v->setDisplay($id) && $v->display_handler->getOption('enabled')) { $result[] = array($v, $id); } @@ -1615,7 +1615,7 @@ function views_get_disabled_views() { * @param mixed $exclude_view * view or current display to exclude * either a - * - views object (containing $exclude_view->name and $exclude_view->current_display) + * - views object (containing $exclude_view->storage->name and $exclude_view->current_display) * - views name as string: e.g. my_view * - views name and display id (separated by ':'): e.g. my_view:default * @param bool $optgroup @@ -1648,7 +1648,7 @@ function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclu $exclude_view_display = ''; } elseif (is_object($exclude_view)) { - $exclude_view_name = $exclude_view->name; + $exclude_view_name = $exclude_view->storage->name; $exclude_view_display = $exclude_view->current_display; } else { @@ -1658,18 +1658,18 @@ function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclu $options = array(); foreach ($views as $view) { // Return only views. - if ($views_only && $view->name != $exclude_view_name) { - $options[$view->name] = $view->getHumanName(); + if ($views_only && $view->storage->name != $exclude_view_name) { + $options[$view->storage->name] = $view->storage->getHumanName(); } // Return views with display ids. else { foreach ($view->display as $display_id => $display) { - if (!($view->name == $exclude_view_name && $display_id == $exclude_view_display)) { + if (!($view->storage->name == $exclude_view_name && $display_id == $exclude_view_display)) { if ($optgroup) { - $options[$view->name][$view->name . ':' . $display['id']] = t('@view : @display', array('@view' => $view->name, '@display' => $display['id'])); + $options[$view->storage->name][$view->storage->name . ':' . $display['id']] = t('@view : @display', array('@view' => $view->storage->name, '@display' => $display['id'])); } else { - $options[$view->name . ':' . $display['id']] = t('View: @view - Display: @display', array('@view' => $view->name, '@display' => $display['id'])); + $options[$view->storage->name . ':' . $display['id']] = t('View: @view - Display: @display', array('@view' => $view->storage->name, '@display' => $display['id'])); } } } @@ -1719,10 +1719,10 @@ function views_view_is_disabled($view) { function views_get_view($name) { $view = entity_load('view', $name); if ($view) { - $executable = new ViewExecutable($view); - $executable->update(); + $view->update(); + $view = $view->getExecutable(); // @figure out whether it makes sense to clone this here. - return $executable->cloneView(); + return $view->cloneView(); } } @@ -1972,7 +1972,7 @@ function views_exposed_form($form, &$form_state) { // Let form plugins know this is for exposed widgets. $form_state['exposed'] = TRUE; // Check if the form was already created - if ($cache = views_exposed_form_cache($view->name, $view->current_display)) { + if ($cache = views_exposed_form_cache($view->storage->name, $view->current_display)) { return $cache; } @@ -2006,12 +2006,12 @@ function views_exposed_form($form, &$form_state) { '#name' => '', '#type' => 'submit', '#value' => t('Apply'), - '#id' => drupal_html_id('edit-submit-' . $view->name), + '#id' => drupal_html_id('edit-submit-' . $view->storage->name), ); $form['#action'] = url($view->display_handler->getUrl()); $form['#theme'] = views_theme_functions('views_exposed_form', $view, $display); - $form['#id'] = drupal_clean_css_identifier('views_exposed_form-' . check_plain($view->name) . '-' . check_plain($display['id'])); + $form['#id'] = drupal_clean_css_identifier('views_exposed_form-' . check_plain($view->storage->name) . '-' . check_plain($display['id'])); // $form['#attributes']['class'] = array('views-exposed-form'); // If using AJAX, we need the form plugin. @@ -2023,7 +2023,7 @@ function views_exposed_form($form, &$form_state) { $exposed_form_plugin->exposed_form_alter($form, $form_state); // Save the form - views_exposed_form_cache($view->name, $view->current_display, $form); + views_exposed_form_cache($view->storage->name, $view->current_display, $form); return $form; } diff --git a/views.tokens.inc b/views.tokens.inc index 4858fbab1809..7d0bf93ccb51 100644 --- a/views.tokens.inc +++ b/views.tokens.inc @@ -58,15 +58,15 @@ function views_tokens($type, $tokens, array $data = array(), array $options = ar foreach ($tokens as $name => $original) { switch ($name) { case 'name': - $replacements[$original] = $sanitize ? check_plain($view->human_name) : $view->human_name; + $replacements[$original] = $sanitize ? check_plain($view->storage->getHumanName()) : $view->storage->getHumanName(); break; case 'description': - $replacements[$original] = $sanitize ? check_plain($view->description) : $view->description; + $replacements[$original] = $sanitize ? check_plain($view->storage->description) : $view->storage->description; break; case 'machine-name': - $replacements[$original] = $view->name; + $replacements[$original] = $view->storage->name; break; case 'title': diff --git a/views_ui.module b/views_ui.module index 362222996c1d..3db82fc7d355 100644 --- a/views_ui.module +++ b/views_ui.module @@ -271,9 +271,9 @@ function views_ui_custom_theme() { function views_ui_edit_page_title($view) { module_load_include('inc', 'views_ui', 'includes/admin'); $bases = views_fetch_base_tables(); - $name = $view->getHumanName(); - if (isset($bases[$view->base_table])) { - $name .= ' (' . $bases[$view->base_table]['title'] . ')'; + $name = $view->storage->getHumanName(); + if (isset($bases[$view->storage->base_table])) { + $name .= ' (' . $bases[$view->storage->base_table]['title'] . ')'; } return $name; @@ -298,7 +298,7 @@ function views_ui_cache_load($name) { $view = $original_view; if (!empty($view)) { // Check to see if someone else is already editing this view. - $view->locked = $views_temp_store->isLocked($view->name); + $view->locked = $views_temp_store->isLocked($view->storage->name); // Set a flag to indicate that this view is being edited. // This flag will be used e.g. to determine whether strings // should be localized. @@ -308,7 +308,7 @@ function views_ui_cache_load($name) { else { // Keep disabled/enabled status real. if ($original_view) { - $view->disabled = $original_view->disabled; + $view->storage->disabled = $original_view->storage->disabled; } } @@ -343,10 +343,8 @@ function views_ui_cache_set(&$view) { unset($view->display_handler); unset($view->default_display); $view->query = NULL; - foreach (array_keys($view->display) as $id) { - unset($view->displayHandlers[$id]); - } - views_temp_store()->set($view->name, $view); + $view->displayHandlers = array(); + views_temp_store()->set($view->storage->name, $view); } /** @@ -475,13 +473,13 @@ function views_ui_view_preview_section_handler_links($view, $type, $title = FALS $field_name = $handler->adminLabel(TRUE); $links[$type . '-edit-' . $id] = array( 'title' => t('Edit @section', array('@section' => $field_name)), - 'href' => "admin/structure/views/nojs/config-item/$view->name/{$display['id']}/$type/$id", + 'href' => "admin/structure/views/nojs/config-item/{$view->storage->name}/{$display['id']}/$type/$id", 'attributes' => array('class' => array('views-ajax-link')), ); } $links[$type . '-add'] = array( 'title' => t('Add new'), - 'href' => "admin/structure/views/nojs/add-item/$view->name/{$display['id']}/$type", + 'href' => "admin/structure/views/nojs/add-item/{$view->storage->name}/{$display['id']}/$type", 'attributes' => array('class' => array('views-ajax-link')), ); @@ -496,7 +494,7 @@ function views_ui_view_preview_section_display_category_links($view, $type, $tit $links = array( $type . '-edit' => array( 'title' => t('Edit @section', array('@section' => $title)), - 'href' => "admin/structure/views/nojs/display/$view->name/{$display['id']}/$type", + 'href' => "admin/structure/views/nojs/display/{$view->storage->name}/{$display['id']}/$type", 'attributes' => array('class' => array('views-ajax-link')), ), ); @@ -598,7 +596,7 @@ function views_ui_get_form_wizard_instance($wizard) { function views_ui_views_plugins_alter(&$plugins) { // @todo This currently does not work, investigate annotation alters. // Attach contextual links to each display plugin. The links will point to - // paths underneath "admin/structure/views/view/{$view->name}" (i.e., paths + // paths underneath "admin/structure/views/view/{$view->storage->name}" (i.e., paths // for editing and performing other contextual actions on the view). foreach ($plugins['display'] as &$display) { $display['contextual links']['views_ui'] = array( diff --git a/views_ui_listing/views_ui_listing.module b/views_ui_listing/views_ui_listing.module index 34a926f189ea..bb08f93e1990 100644 --- a/views_ui_listing/views_ui_listing.module +++ b/views_ui_listing/views_ui_listing.module @@ -63,7 +63,7 @@ function views_ui_listing_entity_listing_page($entity_id) { */ function views_ui_listing_ajax_callback(EntityListControllerInterface $controller, ViewExecutable $entity, $op) { // Perform the operation. - $entity->$op(); + $entity->storage->$op(); // If the request is via AJAX, return the rendered list as JSON. if (drupal_container()->get('request')->request->get('js')) { -- GitLab