function views_service_import in Services 6
Same name and namespace in other branches
- 6.2 services/views_service/views_service.inc \views_service_import()
- 7 services/views_service/views_service.inc \views_service_import()
Import a view.
Parameters
$view_import: Array. The view object.
$view_name: String (optional). The view name.
Return value
Number. The new view ID
1 string reference to 'views_service_import'
- views_service_service in services/
views_service/ views_service.module - Implementation of hook_service().
File
- services/
views_service/ views_service.inc, line 77 - @author Services Dev Team
Code
function views_service_import($view_import, $view_name = '') {
// Include the necessary files
require_once drupal_get_path('module', 'views') . '/includes/admin.inc';
// Import the the views using the same form as in-site import
$form_state['values']['name'] = $view_name;
$form_state['values']['view'] = $view_import;
$form_state['values']['op'] = t('Import');
drupal_execute('views_ui_import_page', $form_state);
// Check if there is a any error
if ($errors = form_set_error()) {
return services_error($errors);
}
// At this point, the new view was only cached and now its time
// to save it and return the new View ID
$view = $form_state['view'];
$view
->save();
return $view->vid;
}