diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Routing/ViewsUIController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Routing/ViewsUIController.php index 2b6ef70..48731d0 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Routing/ViewsUIController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Routing/ViewsUIController.php @@ -193,7 +193,7 @@ public function reportPlugins() { /** * Calls a method on a view and reloads the listing page. * - * @param string|\Drupal\views\ViewStorageInterface $view + * @param \Drupal\views\ViewStorageInterface $view * The view being acted upon. * @param string $op * The operation to perform, e.g., 'enable' or 'disable'. @@ -202,10 +202,7 @@ public function reportPlugins() { * Either returns a rebuilt listing page as an AJAX response, or redirects * back to the listing page. */ - public function ajaxOperation($view, $op, Request $request) { - // @todo Remove this when http://drupal.org/node/1798214 is in. - $view = $this->upcastView($view); - + public function ajaxOperation(ViewStorageInterface $view, $op, Request $request) { // Perform the operation. $view->$op()->save(); @@ -225,34 +222,27 @@ public function ajaxOperation($view, $op, Request $request) { /** * Returns the form to clone a view. * - * @param string|\Drupal\views\ViewStorageInterface $view + * @param \Drupal\views\ViewStorageInterface $view * The view being cloned. * * @return array * The Views clone form. */ - public function cloneForm($view) { - // @todo Remove this when http://drupal.org/node/1798214 is in. - $view = $this->upcastView($view); - + public function cloneForm(ViewStorageInterface $view) { drupal_set_title(t('Clone of @human_name', array('@human_name' => $view->getHumanName()))); - return entity_get_form($view, 'clone'); } /** * Returns the form to delete a view. * - * @param string|\Drupal\views\ViewStorageInterface $view + * @param \Drupal\views\ViewStorageInterface $view * The view being deleted. * * @return array * The Views delete form. */ - public function deleteForm($view) { - // @todo Remove this when http://drupal.org/node/1798214 is in. - $view = $this->upcastView($view); - + public function deleteForm(ViewStorageInterface $view) { return drupal_get_form('views_ui_confirm_delete', $view); } @@ -286,7 +276,7 @@ public function autocompleteTag(Request $request) { /** * Returns the form to edit a view. * - * @param string|\Drupal\views_ui\ViewUI $views_ui + * @param \Drupal\views\ViewStorageInterface $view * The view being deleted. * @param string|null $display_id * (optional) The display ID being edited. Defaults to NULL, which will load @@ -295,27 +285,26 @@ public function autocompleteTag(Request $request) { * @return array * An array containing the Views edit and preview forms. */ - public function edit($views_ui, $display_id = NULL) { - // @todo Replace with proper upcasting. - $view = $this->getViewUI($views_ui); + public function edit(ViewStorageInterface $view, $display_id = NULL) { + $view_ui = $this->getViewUI($view); - $name = $view->getHumanName(); - $data = $this->viewsData->get($view->get('base_table')); + $name = $view_ui->getHumanName(); + $data = $this->viewsData->get($view_ui->get('base_table')); if (isset($data['table']['base']['title'])) { $name .= ' (' . $data['table']['base']['title'] . ')'; } drupal_set_title($name); - $view->displayID = $display_id; - $build['edit'] = entity_get_form($view, 'edit'); - $build['preview'] = entity_get_form($view, 'preview'); + $view_ui->displayID = $display_id; + $build['edit'] = entity_get_form($view_ui, 'edit'); + $build['preview'] = entity_get_form($view_ui, 'preview'); return $build; } /** * Returns the form to preview a view. * - * @param string|\Drupal\views_ui\ViewUI $views_ui + * @param \Drupal\views\ViewStorageInterface $view * The view being deleted. * @param string|null $display_id * (optional) The display ID being edited. Defaults to NULL, which will @@ -324,31 +313,27 @@ public function edit($views_ui, $display_id = NULL) { * @return array * The Views preview form. */ - public function preview($views_ui, $display_id = NULL) { - // @todo Replace with proper upcasting. - $view = $this->getViewUI($views_ui); + public function preview(ViewStorageInterface $view, $display_id = NULL) { + $view_ui = $this->getViewUI($view); - $view->displayID = $display_id; - return entity_get_form($view, 'preview'); + $view_ui->displayID = $display_id; + return entity_get_form($view_ui, 'preview'); } /** * Returns the form to break the lock of an edited view. * - * @param string|\Drupal\views_ui\ViewUI $views_ui + * @param \Drupal\views\ViewStorageInterface $view * The locked view. * * @return array * The Views 'break lock' form. */ - public function breakLock($views_ui) { + public function breakLock(ViewStorageInterface $view) { // @todo Remove the need for this. module_load_include('inc', 'views_ui', 'admin'); - // @todo Replace with proper upcasting. - $view = $this->getViewUI($views_ui); - - return drupal_get_form('views_ui_break_lock_confirm', $view); + return drupal_get_form('views_ui_break_lock_confirm', $this->getViewUI($view)); } /** @@ -360,7 +345,7 @@ public function breakLock($views_ui) { * @param string $key * A string representing a section of the Views UI. Available keys are in * views_ui_ajax_forms(). - * @param \Drupal\views_ui\ViewUI $views_ui + * @param \Drupal\views\ViewStorageInterface $view * The view being edited. * @param string|null $display_id * The display ID being edited, or NULL to load the first available display. @@ -382,82 +367,42 @@ public function breakLock($views_ui) { * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ - public function ajaxForm($js, $key, $views_ui, $display_id, $type, $id) { + public function ajaxForm($js, $key, ViewStorageInterface $view, $display_id, $type, $id) { // Determine if this is an AJAX submission. $js = $js == 'ajax'; // @todo Remove the need for this. module_load_include('inc', 'views_ui', 'admin'); - // @todo Replace with proper upcasting. - $view = $this->getViewUI($views_ui); - - return views_ui_ajax_form($js, $key, $view, $display_id, $type, $id); - } - - /** - * Provides upcasting for View entities until there is generic handling. - * - * @param string|\Drupal\views\ViewStorageInterface $view - * The view being loaded. - * - * @return \Drupal\views\ViewStorageInterface - * The loaded View. - * - * @todo Remove this when http://drupal.org/node/1798214 is committed. - */ - protected function upcastView($view) { - if ($view instanceof ViewStorageInterface) { - return $view; - } - - $results = $this->entityManager->getStorageController('view')->load(array($view)); - $entity = reset($results); - if (!($entity instanceof ViewStorageInterface)) { - throw new \Exception(format_string("Could not load view '@view'.", array('@view' => $view))); - } - return $entity; + return views_ui_ajax_form($js, $key, $this->getViewUI($view), $display_id, $type, $id); } /** * Loads a view, first checking for a view being currently edited. * - * @param string $name - * The machine name of the view. + * @param \Drupal\views\ViewStorageInterface $view + * The view being acted upon. * - * @return \Drupal\views_ui\ViewUI|false - * Either the view object, with a 'locked' property indicating whether or - * not someone else is already editing the view, or FALSE if the view could - * not be loaded. + * @return \Drupal\views_ui\ViewUI + * The view object, with a 'locked' property indicating whether or not + * someone else is already editing the view. */ - public function getViewUI($name) { - $view = $this->tempStore->get($name); - $results = $this->entityManager->getStorageController('view')->load(array($name)); - $original_view = !empty($results) ? new ViewUI(reset($results)) : NULL; - - if (empty($view)) { - $view = $original_view; - if (!empty($view)) { - // Check to see if someone else is already editing this view. - // 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. - $view->editing = TRUE; - } - } - else { + public function getViewUI(ViewStorageInterface $view) { + $view_ui = new ViewUI($view); + if ($new_view = $this->tempStore->get($view_ui->id())) { // Keep disabled/enabled status real. - if ($original_view) { - $view->set('disabled', $original_view->get('disabled')); + if ($view_ui->status()) { + $new_view->enable(); + } + else { + $new_view->disable(); } } - - if (empty($view)) { - return FALSE; + else { + $new_view = $view_ui; } - $view->locked = $this->tempStore->getMetadata($view->id()); - - return $view; + $new_view->locked = $this->tempStore->getMetadata($new_view->id()); + return $new_view; } } diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php index 3c25398..db3634b 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -96,6 +96,13 @@ public function getOperations(EntityInterface $view) { 'weight' => 15, ); + // Restore AJAX functionality to enable/disable operations. + foreach (array('enable', 'disable') as $op) { + if (isset($definition[$op])) { + $definition[$op]['ajax'] = TRUE; + } + } + return $definition; } diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php index 8d8ca11..290899f 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php @@ -98,7 +98,7 @@ protected function actions(array $form, array &$form_state) { public function submitPreview($form, &$form_state) { // Rebuild the form with a pristine $view object. $view = $this->getEntity($form_state); - $form_state['build_info']['args'][0] = drupal_container()->get('views_ui.controller')->getViewUI($view->id()); + $form_state['build_info']['args'][0] = drupal_container()->get('views_ui.controller')->getViewUI($view); $view->renderPreview = TRUE; $form_state['show_preview'] = TRUE; $form_state['rebuild'] = TRUE; diff --git a/core/modules/views/views_ui/views_ui.routing.yml b/core/modules/views/views_ui/views_ui.routing.yml index 6a2f32c..372020e 100644 --- a/core/modules/views/views_ui/views_ui.routing.yml +++ b/core/modules/views/views_ui/views_ui.routing.yml @@ -42,6 +42,9 @@ views_ui.reports.plugins: views_ui.operation: pattern: '/admin/structure/views/view/{view}/{op}' + options: + converters: + view: 'view' defaults: _controller: 'views_ui.controller:ajaxOperation' requirements: @@ -50,6 +53,9 @@ views_ui.operation: views_ui.clone: pattern: '/admin/structure/views/view/{view}/clone' + options: + converters: + view: 'view' defaults: _controller: 'views_ui.controller:cloneForm' requirements: @@ -57,6 +63,9 @@ views_ui.clone: views_ui.delete: pattern: '/admin/structure/views/view/{view}/delete' + options: + converters: + view: 'view' defaults: _controller: 'views_ui.controller:deleteForm' requirements: @@ -70,14 +79,20 @@ views_ui.autocomplete: _permission: 'administer views' views_ui.edit: - pattern: '/admin/structure/views/view/{views_ui}' + pattern: '/admin/structure/views/view/{view}' + options: + converters: + view: 'view' defaults: _controller: 'views_ui.controller:edit' requirements: _permission: 'administer views' views_ui.edit.display: - pattern: '/admin/structure/views/view/{views_ui}/edit/{display_id}' + pattern: '/admin/structure/views/view/{view}/edit/{display_id}' + options: + converters: + view: 'view' defaults: _controller: 'views_ui.controller:edit' display_id: NULL @@ -85,7 +100,10 @@ views_ui.edit.display: _permission: 'administer views' views_ui.preview: - pattern: '/admin/structure/views/view/{views_ui}/preview/{display_id}' + pattern: '/admin/structure/views/view/{view}/preview/{display_id}' + options: + converters: + view: 'view' defaults: _controller: 'views_ui.controller:preview' display_id: NULL @@ -93,7 +111,10 @@ views_ui.preview: _permission: 'administer views' views_ui.breakLock: - pattern: '/admin/structure/views/view/{views_ui}/break-lock' + pattern: '/admin/structure/views/view/{view}/break-lock' + options: + converters: + view: 'view' defaults: _controller: 'views_ui.controller:breakLock' display_id: NULL @@ -101,7 +122,10 @@ views_ui.breakLock: _permission: 'administer views' views_ui.ajaxForm: - pattern: '/admin/structure/views/{js}/{key}/{views_ui}/{display_id}/{type}/{id}' + pattern: '/admin/structure/views/{js}/{key}/{view}/{display_id}/{type}/{id}' + options: + converters: + view: 'view' defaults: _controller: 'views_ui.controller:ajaxForm' type: NULL