t('Views: Import a view from an exported view definition'), ); break; // Validate the values for an action before running the pattern case 'validate': eval($data['view']); if (empty($view)) { watchdog('patterns', "Failed to run pattern to initialize a view ". print_r(get_defined_vars(), 1). print_r(debug_backtrace(), 1)); return "Failed to find the view definition. ". $data['filename']; } break; // Prepare for valid processing of this type of component case 'build': include_once drupal_get_path('module', 'views') .'/includes/admin.inc'; $values = array( 'view' => $data['view'], 'op' => 'Import', 'submit' => 'Import', ); $form_state = array('values' => $values); drupal_execute('views_ui_import_page', $form_state); // At this point the whole view is stored in the UI edit cache // - BUT NOT SAVED YET // I need to Really save the cached thing. // Get it back from cache - it may have appropriate validated bits in it that were missing earlier. eval($data['view']); // Bogus. views internals throws a trivial warning if there is no display set. // fudge that if (empty($view->display)) { $view->display = array(); } // Woo, now we actually know the $view. // Could I have skipped the whole tedious import? probably. if (!empty($view)) { views_ui_cache_load($view->name); @$view->save(); // DONE! } else { watchdog('patterns', "Failed to initialize view to save it" . print_r($values, 1)); } return $data; break; // Build a patterns actions and parameters case 'params': break; case 'cleanup': break; case 'identifier': break; } }