function view::clone_view

cis7 view.inc view::clone_view()
cle7 view.inc view::clone_view()
elmsmedia7 view.inc view::clone_view()
icor7 view.inc view::clone_view()
meedjum_blog7 view.inc view::clone_view()
mooc7 view.inc view::clone_view()

Safely clone a view.

Because views are complicated objects within objects, and PHP loves to do references to everything, if a View is not properly and safely cloned it will still have references to the original view, and can actually cause the original view to point to objects in the cloned view. This gets ugly fast.

This will completely wipe a view clean so it can be considered fresh.

Return value

view The cloned view.

File

sites/all/modules/ulmus/views/includes/view.inc, line 1955
Provides the view object type and associated methods.

Class

view
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.

Code

function clone_view() {
  $clone = version_compare(phpversion(), '5.0') < 0 ? $this : clone($this);

  $keys = array(
    'current_display',
    'display_handler',
    '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) {
    if (isset($clone->$key)) {
      unset($clone->$key);
    }
  }
  $clone->built = $clone->executed = FALSE;
  $clone->build_info = array();
  $clone->attachment_before = '';
  $clone->attachment_after = '';
  $clone->result = array();

  // shallow cloning means that all the display objects
  // *were not cloned*. We must clone them ourselves.
  $displays = array();
  foreach ($clone->display as $id => $display) {
    $displays[$id] = clone $display;
    if (isset($displays[$id]->handler)) {
      unset($displays[$id]->handler);
    }
  }
  $clone->display = $displays;

  return $clone;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.