diff --git a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php
new file mode 100644
index 0000000..ad518b8
--- /dev/null
+++ b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php
@@ -0,0 +1,399 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\views\Plugin\Core\Entity\View.
+ */
+
+namespace Drupal\views\Plugin\Core\Entity;
+
+use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\views_ui\ViewUI;
+use Drupal\views\ViewStorageInterface;
+use Drupal\views\ViewExecutable;
+use Drupal\Core\Annotation\Plugin;
+use Drupal\Core\Annotation\Translation;
+
+/**
+ * Defines a View configuration entity class.
+ *
+ * @Plugin(
+ *   id = "view",
+ *   label = @Translation("View"),
+ *   module = "views",
+ *   controller_class = "Drupal\views\ViewStorageController",
+ *   list_controller_class = "Drupal\views_ui\ViewListController",
+ *   form_controller_class = {
+ *     "edit" = "Drupal\views_ui\ViewEditFormController",
+ *     "add" = "Drupal\views_ui\ViewAddFormController",
+ *     "preview" = "Drupal\views_ui\ViewPreviewFormController",
+ *     "clone" = "Drupal\views_ui\ViewCloneFormController"
+ *   },
+ *   config_prefix = "views.view",
+ *   fieldable = FALSE,
+ *   entity_keys = {
+ *     "id" = "name",
+ *     "label" = "human_name",
+ *     "uuid" = "uuid"
+ *   }
+ * )
+ */
+class View extends ConfigEntityBase implements ViewStorageInterface {
+
+  /**
+   * The name of the base table this view will use.
+   *
+   * @var string
+   */
+  protected $base_table = 'node';
+
+  /**
+   * The name of the view.
+   *
+   * @var string
+   */
+  public $name = '';
+
+  /**
+   * The description of the view, which is used only in the interface.
+   *
+   * @var string
+   */
+  protected $description = '';
+
+  /**
+   * The "tags" of a view.
+   *
+   * The tags are stored as a single string, though it is used as multiple tags
+   * for example in the views overview.
+   *
+   * @var string
+   */
+  protected $tag = '';
+
+  /**
+   * The human readable name of the view.
+   *
+   * @var string
+   */
+  public $human_name = '';
+
+  /**
+   * The core version the view was created for.
+   *
+   * @var int
+   */
+  protected $core = DRUPAL_CORE_COMPATIBILITY;
+
+  /**
+   * The views API version this view was created by.
+   *
+   * @var string
+   */
+  protected $api_version = VIEWS_API_VERSION;
+
+  /**
+   * Stores all display handlers of this view.
+   *
+   * An array containing Drupal\views\Plugin\views\display\DisplayPluginBase
+   * objects.
+   *
+   * @var array
+   */
+  protected $display;
+
+  /**
+   * The name of the base field to use.
+   *
+   * @var string
+   */
+  protected $base_field = 'nid';
+
+  /**
+   * Returns whether the view's status is disabled or not.
+   *
+   * This value is used for exported view, to provide some default views which
+   * aren't enabled.
+   *
+   * @var bool
+   */
+  protected $disabled = FALSE;
+
+  /**
+   * The UUID for this entity.
+   *
+   * @var string
+   */
+  public $uuid = NULL;
+
+  /**
+   * Stores a reference to the executable version of this view.
+   *
+   * @var Drupal\views\ViewExecutable
+   */
+  protected $executable;
+
+  /**
+   * The module implementing this view.
+   *
+   * @var string
+   */
+  protected $module = 'views';
+
+  /**
+   * Overrides Drupal\Core\Entity\EntityInterface::get().
+   */
+  public function get($property_name, $langcode = NULL) {
+    // Ensure that an executable View is available.
+    if ($property_name == 'executable' && !isset($this->{$property_name})) {
+      $this->set('executable', new ViewExecutable($this));
+    }
+
+    return parent::get($property_name, $langcode);
+  }
+
+  /**
+   * Overrides Drupal\Core\Entity\EntityInterface::uri().
+   */
+  public function uri() {
+    return array(
+      'path' => 'admin/structure/views/view/' . $this->id(),
+    );
+  }
+
+  /**
+   * Overrides Drupal\Core\Entity\EntityInterface::id().
+   */
+  public function id() {
+    return $this->get('name');
+  }
+
+  /**
+   * Implements Drupal\views\ViewStorageInterface::enable().
+   */
+  public function enable() {
+    $this->disabled = FALSE;
+    $this->save();
+  }
+
+  /**
+   * Implements Drupal\views\ViewStorageInterface::disable().
+   */
+  public function disable() {
+    $this->disabled = TRUE;
+    $this->save();
+  }
+
+  /**
+   * Implements Drupal\views\ViewStorageInterface::isEnabled().
+   */
+  public function isEnabled() {
+    return !$this->disabled;
+  }
+
+  /**
+   * Return the human readable name for a view.
+   *
+   * When a certain view doesn't have a human readable name return the machine readable name.
+   */
+  public function getHumanName() {
+    if (!$human_name = $this->get('human_name')) {
+      $human_name = $this->get('name');
+    }
+    return $human_name;
+  }
+
+  /**
+   * Adds a new display handler to the view, automatically creating an ID.
+   *
+   * @param string $plugin_id
+   *   (optional) The plugin type from the Views plugin annotation. Defaults to
+   *   'page'.
+   * @param string $title
+   *   (optional) The title of the display. Defaults to NULL.
+   * @param string $id
+   *   (optional) The ID to use, e.g., 'default', 'page_1', 'block_2'. Defaults
+   *   to NULL.
+   *
+   * @return string|false
+   *   The key to the display in $view->display, or FALSE if no plugin ID was
+   *   provided.
+   */
+  public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
+    if (empty($plugin_id)) {
+      return FALSE;
+    }
+
+    $plugin = drupal_container()->get('plugin.manager.views.display')->getDefinition($plugin_id);
+    if (empty($plugin)) {
+      $plugin['title'] = t('Broken');
+    }
+
+    if (empty($id)) {
+      $id = $this->generateDisplayId($plugin_id);
+
+      // Generate a unique human-readable name by inspecting the counter at the
+      // end of the previous display ID, e.g., 'page_1'.
+      if ($id !== 'default') {
+        preg_match("/[0-9]+/", $id, $count);
+        $count = $count[0];
+      }
+      else {
+        $count = '';
+      }
+
+      if (empty($title)) {
+        // If there is no title provided, use the plugin title, and if there are
+        // multiple displays, append the count.
+        $title = $plugin['title'];
+        if ($count > 1) {
+          $title .= ' ' . $count;
+        }
+      }
+    }
+
+    $display_options = array(
+      'display_plugin' => $plugin_id,
+      'id' => $id,
+      'display_title' => $title,
+      'position' => NULL,
+      'display_options' => array(),
+    );
+
+    // Add the display options to the view.
+    $this->display[$id] = $display_options;
+    return $id;
+  }
+
+  /**
+   * Generates a display ID of a certain plugin type.
+   *
+   * @param string $plugin_id
+   *   Which plugin should be used for the new display ID.
+   */
+  protected function generateDisplayId($plugin_id) {
+    // 'default' is singular and is unique, so just go with 'default'
+    // for it. For all others, start counting.
+    if ($plugin_id == 'default') {
+      return 'default';
+    }
+    // Initial ID.
+    $id = $plugin_id . '_1';
+    $count = 1;
+
+    // Loop through IDs based upon our style plugin name until
+    // we find one that is unused.
+    while (!empty($this->display[$id])) {
+      $id = $plugin_id . '_' . ++$count;
+    }
+
+    return $id;
+  }
+
+  /**
+   * Creates a new display and a display handler for it.
+   *
+   * @param string $plugin_id
+   *   (optional) The plugin type from the Views plugin annotation. Defaults to
+   *   'page'.
+   * @param string $title
+   *   (optional) The title of the display. Defaults to NULL.
+   * @param string $id
+   *   (optional) The ID to use, e.g., 'default', 'page_1', 'block_2'. Defaults
+   *   to NULL.
+   *
+   * @return Drupal\views\Plugin\views\display\DisplayPluginBase
+   *   A reference to the new handler object.
+   */
+  public function &newDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
+    $id = $this->addDisplay($plugin_id, $title, $id);
+    return $this->get('executable')->newDisplay($id);
+  }
+
+  /**
+   * Retrieves a specific display's configuration by reference.
+   *
+   * @param string $display_id
+   *   The display ID to retrieve, e.g., 'default', 'page_1', 'block_2'.
+   *
+   * @return array
+   *   A reference to the specified display configuration.
+   */
+  public function &getDisplay($display_id) {
+    return $this->display[$display_id];
+  }
+
+  /**
+   * Gets a list of displays included in the view.
+   *
+   * @return array
+   *   An array of display types that this view includes.
+   */
+  function getDisplaysList() {
+    $manager = drupal_container()->get('plugin.manager.views.display');
+    $displays = array();
+    foreach ($this->display as $display) {
+      $definition = $manager->getDefinition($display['display_plugin']);
+      if (!empty($definition['admin'])) {
+        $displays[$definition['admin']] = TRUE;
+      }
+    }
+
+    ksort($displays);
+    return array_keys($displays);
+  }
+
+  /**
+   * Gets a list of paths assigned to the view.
+   *
+   * @return array
+   *   An array of paths for this view.
+   */
+  public function getPaths() {
+    $all_paths = array();
+    if (empty($this->display)) {
+      $all_paths[] = t('Edit this view to add a display.');
+    }
+    else {
+      foreach ($this->display as $display) {
+        if (!empty($display['display_options']['path'])) {
+          $path = $display['display_options']['path'];
+          if ($this->isEnabled() && strpos($path, '%') === FALSE) {
+            $all_paths[] = l('/' . $path, $path);
+          }
+          else {
+            $all_paths[] = check_plain('/' . $path);
+          }
+        }
+      }
+    }
+
+    return array_unique($all_paths);
+  }
+
+  /**
+   * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties();
+   */
+  public function getExportProperties() {
+    $names = array(
+      'api_version',
+      'base_field',
+      'base_table',
+      'core',
+      'description',
+      'disabled',
+      'display',
+      'human_name',
+      'module',
+      'name',
+      'tag',
+      'uuid',
+    );
+    $properties = array();
+    foreach ($names as $name) {
+      $properties[$name] = $this->get($name);
+    }
+    return $properties;
+  }
+
+}
diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php
new file mode 100644
index 0000000..5692b7e
--- /dev/null
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php
@@ -0,0 +1,286 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\views\Plugin\views\display\PathPluginBase.
+ */
+
+namespace Drupal\views\Plugin\views\display;
+
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+
+/**
+ * The base display plugin for path/callbacks. This is used for pages, feeds.
+ */
+abstract class PathPluginBase extends DisplayPluginBase {
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::hasPath().
+   */
+  public function hasPath() {
+    return TRUE;
+  }
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase:defineOptions().
+   */
+  protected function defineOptions() {
+    $options = parent::defineOptions();
+    $options['path'] = array('default' => '');
+
+    return $options;
+  }
+
+  /**
+   * Add this display's path information to Drupal's menu system.
+   */
+  public function executeHookMenu($callbacks) {
+    $items = array();
+    // Replace % with the link to our standard views argument loader
+    // views_arg_load -- which lives in views.module
+
+    $bits = explode('/', $this->getOption('path'));
+    $page_arguments = array($this->view->storage->name, $this->display['id']);
+    $this->view->initHandlers();
+    $view_arguments = $this->view->argument;
+
+    // Replace % with %views_arg for menu autoloading and add to the
+    // page arguments so the argument actually comes through.
+    foreach ($bits as $pos => $bit) {
+      if ($bit == '%') {
+        $argument = array_shift($view_arguments);
+        if (!empty($argument->options['specify_validation']) && $argument->options['validate']['type'] != 'none') {
+          $bits[$pos] = '%views_arg';
+        }
+        $page_arguments[] = $pos;
+      }
+    }
+
+    $path = implode('/', $bits);
+
+    $access_plugin = $this->getPlugin('access');
+    if (!isset($access_plugin)) {
+      $access_plugin = drupal_container()->get("plugin.manager.views.access")->createInstance('none');
+    }
+
+    // Get access callback might return an array of the callback + the dynamic arguments.
+    $access_plugin_callback = $access_plugin->get_access_callback();
+
+    if (is_array($access_plugin_callback)) {
+      $access_arguments = array();
+
+      // Find the plugin arguments.
+      $access_plugin_method = array_shift($access_plugin_callback);
+      $access_plugin_arguments = array_shift($access_plugin_callback);
+      if (!is_array($access_plugin_arguments)) {
+        $access_plugin_arguments = array();
+      }
+
+      $access_arguments[0] = array($access_plugin_method, &$access_plugin_arguments);
+
+      // Move the plugin arguments to the access arguments array.
+      $i = 1;
+      foreach ($access_plugin_arguments as $key => $value) {
+        if (is_int($value)) {
+          $access_arguments[$i] = $value;
+          $access_plugin_arguments[$key] = $i;
+          $i++;
+        }
+      }
+    }
+    else {
+      $access_arguments = array($access_plugin_callback);
+    }
+
+    if ($path) {
+      $items[$path] = array(
+        // default views page entry
+        'page callback' => 'views_page',
+        'page arguments' => $page_arguments,
+        // Default access check (per display)
+        'access callback' => 'views_access',
+        'access arguments' => $access_arguments,
+        // Identify URL embedded arguments and correlate them to a handler
+        'load arguments'  => array($this->view->storage->name, $this->display['id'], '%index'),
+      );
+      $menu = $this->getOption('menu');
+      if (empty($menu)) {
+        $menu = array('type' => 'none');
+      }
+      // Set the title and description if we have one.
+      if ($menu['type'] != 'none') {
+        $items[$path]['title'] = $menu['title'];
+        $items[$path]['description'] = $menu['description'];
+      }
+
+      if (isset($menu['weight'])) {
+        $items[$path]['weight'] = intval($menu['weight']);
+      }
+
+      switch ($menu['type']) {
+        case 'none':
+        default:
+          $items[$path]['type'] = MENU_CALLBACK;
+          break;
+        case 'normal':
+          $items[$path]['type'] = MENU_NORMAL_ITEM;
+          // Insert item into the proper menu
+          $items[$path]['menu_name'] = $menu['name'];
+          break;
+        case 'tab':
+          $items[$path]['type'] = MENU_LOCAL_TASK;
+          break;
+        case 'default tab':
+          $items[$path]['type'] = MENU_DEFAULT_LOCAL_TASK;
+          break;
+      }
+
+      // Add context for contextual links.
+      // @see menu_contextual_links()
+      if (!empty($menu['context'])) {
+        $items[$path]['context'] = MENU_CONTEXT_INLINE;
+      }
+
+      // If this is a 'default' tab, check to see if we have to create teh
+      // parent menu item.
+      if ($menu['type'] == 'default tab') {
+        $tab_options = $this->getOption('tab_options');
+        if (!empty($tab_options['type']) && $tab_options['type'] != 'none') {
+          $bits = explode('/', $path);
+          // Remove the last piece.
+          $bit = array_pop($bits);
+
+          // we can't do this if they tried to make the last path bit variable.
+          // @todo: We can validate this.
+          if ($bit != '%views_arg' && !empty($bits)) {
+            $default_path = implode('/', $bits);
+            $items[$default_path] = array(
+              // default views page entry
+              'page callback' => 'views_page',
+              'page arguments' => $page_arguments,
+              // Default access check (per display)
+              'access callback' => 'views_access',
+              'access arguments' => $access_arguments,
+              // Identify URL embedded arguments and correlate them to a handler
+              'load arguments'  => array($this->view->storage->name, $this->display['id'], '%index'),
+              'title' => $tab_options['title'],
+              'description' => $tab_options['description'],
+              'menu_name' => $tab_options['name'],
+            );
+            switch ($tab_options['type']) {
+              default:
+              case 'normal':
+                $items[$default_path]['type'] = MENU_NORMAL_ITEM;
+                break;
+              case 'tab':
+                $items[$default_path]['type'] = MENU_LOCAL_TASK;
+                break;
+            }
+            if (isset($tab_options['weight'])) {
+              $items[$default_path]['weight'] = intval($tab_options['weight']);
+            }
+          }
+        }
+      }
+    }
+
+    return $items;
+  }
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::execute().
+   */
+  public function execute() {
+    // Prior to this being called, the $view should already be set to this
+    // display, and arguments should be set on the view.
+    $this->view->build();
+
+    if (!empty($this->view->build_info['fail'])) {
+      throw new NotFoundHttpException();
+    }
+
+    if (!empty($this->view->build_info['denied'])) {
+      throw new AccessDeniedHttpException();
+    }
+  }
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummary().
+   */
+  public function optionsSummary(&$categories, &$options) {
+    parent::optionsSummary($categories, $options);
+
+    $categories['page'] = array(
+      'title' => t('Page settings'),
+      'column' => 'second',
+      'build' => array(
+        '#weight' => -10,
+      ),
+    );
+
+    $path = strip_tags($this->getOption('path'));
+
+    if (empty($path)) {
+      $path = t('No path is set');
+    }
+    else {
+      $path = '/' . $path;
+    }
+
+    $options['path'] = array(
+      'category' => 'page',
+      'title' => t('Path'),
+      'value' => views_ui_truncate($path, 24),
+    );
+  }
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::buildOptionsForm()..
+   */
+  public function buildOptionsForm(&$form, &$form_state) {
+    parent::buildOptionsForm($form, $form_state);
+
+    switch ($form_state['section']) {
+      case 'path':
+        $form['#title'] .= t('The menu path or URL of this view');
+        $form['path'] = array(
+          '#type' => 'textfield',
+          '#description' => t('This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for contextual filters: For example, "node/%/feed".'),
+          '#default_value' => $this->getOption('path'),
+          '#field_prefix' => '<span dir="ltr">' . url(NULL, array('absolute' => TRUE)),
+          '#field_suffix' => '</span>&lrm;',
+          '#attributes' => array('dir' => 'ltr'),
+        );
+        break;
+    }
+  }
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm().
+   */
+  public function validateOptionsForm(&$form, &$form_state) {
+    parent::validateOptionsForm($form, $form_state);
+
+    if ($form_state['section'] == 'path') {
+      if (strpos($form_state['values']['path'], '%') === 0) {
+        form_error($form['path'], t('"%" may not be used for the first segment of a path.'));
+      }
+
+      // Automatically remove '/' and trailing whitespace from path.
+      $form_state['values']['path'] = trim($form_state['values']['path'], '/ ');
+    }
+  }
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::submitOptionsForm().
+   */
+  public function submitOptionsForm(&$form, &$form_state) {
+    parent::submitOptionsForm($form, $form_state);
+
+    if ($form_state['section'] == 'path') {
+      $this->setOption('path', $form_state['values']['path']);
+    }
+  }
+
+}
diff --git a/core/modules/views/lib/Drupal/views/ViewRenderController.php b/core/modules/views/lib/Drupal/views/ViewRenderController.php
new file mode 100644
index 0000000..e27f84b
--- /dev/null
+++ b/core/modules/views/lib/Drupal/views/ViewRenderController.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\views\ViewRenderController.
+ */
+
+namespace Drupal\views;
+
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityRenderController;
+
+/**
+ * Render controller for views.
+ */
+class ViewRenderController extends EntityRenderController {
+
+  /**
+   * Overrides \Drupal\Core\Entity\EntityRenderController::buildContent().
+   */
+  public function buildContent(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
+    parent::buildContent($entities, $view_mode, $langcode);
+
+    // Unset any pre-render callbacks that might conflict with the view.
+    foreach ($entities as $key => $entity) {
+      unset($entity->content['#pre_render']);
+    }
+  }
+
+  /**
+   * Overrides \Drupal\Core\Entity\EntityRenderController::getBuildDefaults().
+   */
+  protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) {
+    return array(
+      '#type' => $this->entityType,
+      "#{$this->entityType}" => $entity->get('executable'),
+      '#display_id' => $entity->displayId,
+      '#arguments' => $entity->arguments,
+    );
+    return $return;
+  }
+
+}
diff --git a/core/modules/views/views.module b/core/modules/views/views.module
index e1a4d8c..35e8f9c 100644
--- a/core/modules/views/views.module
+++ b/core/modules/views/views.module
@@ -74,6 +74,46 @@ function views_views_pre_render($view) {
 
   return $view;
 }
+/**
+ * Implements hook_element_info().
+ */
+function views_element_info() {
+  $types['view'] = array(
+    '#theme_wrappers' => array('container'),
+    '#pre_render' => array('views_pre_render_view_element'),
+    '#name' => NULL,
+    '#display_id' => 'default',
+    '#arguments' => array(),
+  );
+  return $types;
+}
+
+/**
+ * View element pre render callback.
+ */
+function views_pre_render_view_element($element) {
+  $element['#attributes']['class'][] = 'views-element-container';
+
+  $view = views_get_view($element['#name']);
+  if ($view && $view->access($element['#display_id'])) {
+    $element['view']['#markup'] = $view->preview($element['#display_id'], $element['#arguments']);
+  }
+
+  return $element;
+}
+
+/**
+ * Implements hook_config_import_create().
+ */
+function views_config_import_create($name, $new_config, $old_config) {
+  if (strpos($name, 'views.view.') !== 0) {
+    return FALSE;
+  }
+
+  $view = entity_create('view', $new_config->get());
+  $view->save();
+  return TRUE;
+}
 
 /**
  * Implements hook_theme().
@@ -288,7 +328,292 @@ function views_theme_suggestions_comment_alter(array &$suggestions, array $varia
  */
 function views_theme_suggestions_container_alter(array &$suggestions, array $variables) {
   if (!empty($variables['element']['#type']) && $variables['element']['#type'] == 'more_link' && !empty($variables['element']['#view']) && $variables['element']['#view'] instanceof ViewExecutable) {
-    $suggestions = array_merge($suggestions, $variables['element']['#view']->buildThemeFunctions('container__more_link'));
+      $suggestions = array_merge($suggestions, $variables['element']['#view']->buildThemeFunctions('container__more_link'));
+  }
+}
+
+/**
+ * Helper function for menu loading. This will automatically be
+ * called in order to 'load' a views argument; primarily it
+ * will be used to perform validation.
+ *
+ * @param $value
+ *   The actual value passed.
+ * @param $name
+ *   The name of the view. This needs to be specified in the 'load function'
+ *   of the menu entry.
+ * @param $display_id
+ *   The display id that will be loaded for this menu item.
+ * @param $index
+ *   The menu argument index. This counts from 1.
+ */
+
+function views_arg_load($value, $name, $display_id, $index) {
+  static $views = array();
+
+  // Make sure we haven't already loaded this views argument for a similar menu
+  // item elsewhere.
+  $key = $name . ':' . $display_id . ':' . $value . ':' . $index;
+  if (isset($views[$key])) {
+    return $views[$key];
+  }
+
+  if ($view = views_get_view($name)) {
+    $view->setDisplay($display_id);
+    $view->initHandlers();
+
+    $ids = array_keys($view->argument);
+
+    $indexes = array();
+    $path = explode('/', $view->getPath());
+
+    foreach ($path as $id => $piece) {
+      if ($piece == '%' && !empty($ids)) {
+        $indexes[$id] = array_shift($ids);
+      }
+    }
+
+    if (isset($indexes[$index])) {
+      if (isset($view->argument[$indexes[$index]])) {
+        $arg = $view->argument[$indexes[$index]]->validate_argument($value) ? $value : FALSE;
+        $view->destroy();
+
+        // Store the output in case we load this same menu item again.
+        $views[$key] = $arg;
+        return $arg;
+      }
+    }
+    $view->destroy();
+  }
+}
+
+/**
+ * Page callback: Displays a page view, given a name and display id.
+ *
+ * @param $name
+ *   The name of a view.
+ * @param $display_id
+ *   The display id of a view.
+ *
+ * @return
+ *   Either the HTML of a fully-executed view, or MENU_NOT_FOUND.
+ */
+function views_page($name, $display_id) {
+  $args = func_get_args();
+  // Remove $name and $display_id from the arguments.
+  array_shift($args);
+  array_shift($args);
+
+  // Load the view and render it.
+  if ($view = views_get_view($name)) {
+    return $view->executeDisplay($display_id, $args);
+  }
+
+  // Fallback; if we get here no view was found or handler was not valid.
+  return MENU_NOT_FOUND;
+}
+
+/**
+ * Implements hook_page_alter().
+ */
+function views_page_alter(&$page) {
+  // If the main content of this page contains a view, attach its contextual
+  // links to the overall page array. This allows them to be rendered directly
+  // next to the page title.
+  if ($view = views_get_page_view()) {
+    views_add_contextual_links($page, 'page', $view, $view->current_display);
+  }
+}
+
+/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function views_preprocess_html(&$variables) {
+  // If the page contains a view as its main content, contextual links may have
+  // been attached to the page as a whole; for example, by views_page_alter().
+  // This allows them to be associated with the page and rendered by default
+  // next to the page title (which we want). However, it also causes the
+  // Contextual Links module to treat the wrapper for the entire page (i.e.,
+  // the <body> tag) as the HTML element that these contextual links are
+  // associated with. This we don't want; for better visual highlighting, we
+  // prefer a smaller region to be chosen. The region we prefer differs from
+  // theme to theme and depends on the details of the theme's markup in
+  // page.tpl.php, so we can only find it using JavaScript. We therefore remove
+  // the "contextual-region" class from the <body> tag here and add
+  // JavaScript that will insert it back in the correct place.
+  if (!empty($variables['page']['#views_contextual_links_info'])) {
+    $key = array_search('contextual-region', $variables['attributes']['class']->value());
+    if ($key !== FALSE) {
+      unset($variables['attributes']['class'][$key]);
+      // Add the JavaScript, with a group and weight such that it will run
+      // before modules/contextual/contextual.js.
+      drupal_add_js(drupal_get_path('module', 'views') . '/js/views-contextual.js', array('group' => JS_LIBRARY, 'weight' => -1));
+    }
+  }
+}
+
+/**
+ * Implements hook_contextual_links_view_alter().
+ */
+function views_contextual_links_view_alter(&$element, $items) {
+  // If we are rendering views-related contextual links attached to the overall
+  // page array, add a class to the list of contextual links. This will be used
+  // by the JavaScript added in views_preprocess_html().
+  if (!empty($element['#element']['#views_contextual_links_info']) && !empty($element['#element']['#type']) && $element['#element']['#type'] == 'page') {
+    $element['#attributes']['class'][] = 'views-contextual-links-page';
+  }
+}
+
+/**
+ * Implement hook_block_info().
+ */
+function views_block_info() {
+  // Try to avoid instantiating all the views just to get the blocks info.
+  views_include('cache');
+  $cache = views_cache_get('views_block_items', TRUE);
+  if ($cache && is_array($cache->data)) {
+    return $cache->data;
+  }
+
+  $items = array();
+  $views = views_get_all_views();
+  foreach ($views as $view) {
+    // disabled views get nothing.
+    if (!$view->isEnabled()) {
+      continue;
+    }
+
+    $executable = $view->get('executable');
+    $executable->initDisplay();
+    foreach ($executable->displayHandlers as $display) {
+
+      if (isset($display) && !empty($display->definition['uses_hook_block'])) {
+        $result = $display->executeHookBlockList();
+        if (is_array($result)) {
+          $items = array_merge($items, $result);
+        }
+      }
+
+      if (isset($display) && $display->getOption('exposed_block')) {
+        $result = $display->getSpecialBlocks();
+        if (is_array($result)) {
+          $items = array_merge($items, $result);
+        }
+      }
+    }
+  }
+
+  // block.module has a delta length limit of 32, but our deltas can
+  // unfortunately be longer because view names can be 32 and display IDs
+  // can also be 32. So for very long deltas, change to md5 hashes.
+  $hashes = array();
+
+  // get the keys because we're modifying the array and we don't want to
+  // confuse PHP too much.
+  $keys = array_keys($items);
+  foreach ($keys as $delta) {
+    if (strlen($delta) >= 32) {
+      $hash = md5($delta);
+      $hashes[$hash] = $delta;
+      $items[$hash] = $items[$delta];
+      unset($items[$delta]);
+    }
+  }
+
+  // Only save hashes if they have changed.
+  $old_hashes = state()->get('views_block_hashes');
+  if ($hashes != $old_hashes) {
+    state()->set('views_block_hashes', $hashes);
+  }
+
+  views_cache_set('views_block_items', $items, TRUE);
+
+  return $items;
+}
+
+/**
+ * Implement hook_block_view().
+ */
+function views_block_view($delta) {
+  $start = microtime(TRUE);
+  // if this is 32, this should be an md5 hash.
+  if (strlen($delta) == 32) {
+    $hashes = state()->get('views_block_hashes');
+    if (!empty($hashes[$delta])) {
+      $delta = $hashes[$delta];
+    }
+  }
+
+  // This indicates it's a special one.
+  if (substr($delta, 0, 1) == '-') {
+    list($nothing, $type, $name, $display_id) = explode('-', $delta);
+    // Put the - back on.
+    $type = '-' . $type;
+    if ($view = views_get_view($name)) {
+      if ($view->access($display_id)) {
+        $view->setDisplay($display_id);
+        if (isset($view->display_handler)) {
+          $output = $view->display_handler->viewSpecialBlocks($type);
+          // Before returning the block output, convert it to a renderable
+          // array with contextual links.
+          views_add_block_contextual_links($output, $view, $display_id, 'special_block_' . $type);
+          $view->destroy();
+          return $output;
+        }
+      }
+      $view->destroy();
+    }
+  }
+
+  // If the delta doesn't contain valid data return nothing.
+  $explode = explode('-', $delta);
+  if (count($explode) != 2) {
+    return;
+  }
+  list($name, $display_id) = $explode;
+  // Load the view
+  if ($view = views_get_view($name)) {
+    if ($view->access($display_id)) {
+      $output = $view->executeDisplay($display_id);
+      // Before returning the block output, convert it to a renderable array
+      // with contextual links.
+      views_add_block_contextual_links($output, $view, $display_id);
+      $view->destroy();
+      return $output;
+    }
+    $view->destroy();
+  }
+}
+
+/**
+ * Converts Views block content to a renderable array with contextual links.
+ *
+ * @param $block
+ *   An array representing the block, with the same structure as the return
+ *   value of hook_block_view(). This will be modified so as to force
+ *   $block['content'] to be a renderable array, containing the optional
+ *   '#contextual_links' property (if there are any contextual links associated
+ *   with the block).
+ * @param $view
+ *   The view that was used to generate the block content.
+ * @param $display_id
+ *   The ID of the display within the view that was used to generate the block
+ *   content.
+ * @param $block_type
+ *   The type of the block. If it's block it's a regular views display,
+ *   but 'special_block_-exp' exist as well.
+ */
+function views_add_block_contextual_links(&$block, ViewExecutable $view, $display_id, $block_type = 'block') {
+  // Do not add contextual links to an empty block.
+  if (!empty($block['content'])) {
+    // Contextual links only work on blocks whose content is a renderable
+    // array, so if the block contains a string of already-rendered markup,
+    // convert it to an array.
+    if (is_string($block['content'])) {
+      $block['content'] = array('#markup' => $block['content']);
+    }
+    // Add the contextual links.
+    views_add_contextual_links($block['content'], $block_type, $view, $display_id);
   }
 }
 
