From 09183ab633e05c2fef41e0a6480c88b9cb287aa5 Mon Sep 17 00:00:00 2001
From: Damian Lee <damian@damoweb.co.uk>
Date: Sat, 6 Oct 2012 13:52:05 +0100
Subject: [PATCH] Issue #1804178 by damiankloip: Add views_create_view()
 wrapper function and update view creation code in instantiate_plugin() method
 of WizardPluginBase.

---
 .../Plugin/views/wizard/WizardPluginBase.php  | 21 ++++++++++---------
 views.module                                  | 12 ++++++++++-
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
index c85bc80ec1cd..03f62eeef9d7 100644
--- a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
+++ b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
@@ -543,18 +543,19 @@ protected function build_sorts(&$form, &$form_state) {
   /**
    * Instantiates a view object from form values.
    *
-   * @return Drupal\views\ViewExecutable
-   *   The instantiated view object.
+   * @return Drupal\views_ui\ViewUI
+   *   The instantiated view UI object.
    */
   protected function instantiate_view($form, &$form_state) {
-    // Build the basic view properties.
-    $view = views_new_view();
-    $view->name = $form_state['values']['name'];
-    $view->human_name = $form_state['values']['human_name'];
-    $view->description = $form_state['values']['description'];
-    $view->tag = 'default';
-    $view->core = VERSION;
-    $view->base_table = $this->base_table;
+    // Build the basic view properties and create the view.
+    $values = array(
+      'name' => $form_state['values']['name'],
+      'human_name' => $form_state['values']['human_name'],
+      'description' => $form_state['values']['description'],
+      'base_table' => $this->base_table,
+    );
+
+    $view = views_create_view($values);
 
     // Build all display options for this view.
     $display_options = $this->build_display_options($form, $form_state);
diff --git a/views.module b/views.module
index e146740a7417..75c4657dafca 100644
--- a/views.module
+++ b/views.module
@@ -1516,7 +1516,7 @@ function views_get_enabled_display_extenders() {
 /**
  * Create an empty view to work with.
  *
- * @return Drupal\views\ViewExecutable
+ * @return Drupal\views\ViewStorage
  *   A fully formed, empty $view object. This object must be populated before
  *   it can be successfully saved.
  */
@@ -1524,6 +1524,16 @@ function views_new_view() {
   return entity_create('view', array());
 }
 
+/**
+ * Creates a view from an array of values.
+ *
+ * @return Drupal\views\ViewStorage
+ *   A fully formed $view object with properties from the values passed in.
+ */
+function views_create_view(array $values = array()) {
+  return entity_create('view', $values);
+}
+
 /**
  * Return a list of all views and display IDs that have a particular
  * setting in their display's plugin settings.
-- 
GitLab