function views_ui_import_validate
Validate handler to import a view.
1 string reference to 'views_ui_import_validate'
- views_ui_import_page in includes/
admin.inc - Import a view from cut & paste.
File
-
includes/
admin.inc, line 2140
Code
function views_ui_import_validate($form, &$form_state) {
$view = '';
views_include('view');
// Be forgiving if someone pastes views code that starts with '<?php'.
if (substr($form_state['values']['view'], 0, 5) == '<?php') {
$form_state['values']['view'] = substr($form_state['values']['view'], 5);
}
ob_start();
eval($form_state['values']['view']);
ob_end_clean();
if (!is_object($view)) {
return form_error($form['view'], t('Unable to interpret view code.'));
}
if (empty($view->api_version) || $view->api_version < 2) {
form_error($form['view'], t('That view is not compatible with this version of Views.
If you have a view from views1 you have to go to a drupal6 installation and import it there.'));
}
elseif (version_compare($view->api_version, views_api_version(), '>')) {
form_error($form['view'], t('That view is created for the version @import_version of views, but you only have @api_version', array(
'@import_version' => $view->api_version,
'@api_version' => views_api_version(),
)));
}
// View name must be alphanumeric or underscores, no other punctuation.
if (!empty($form_state['values']['name']) && preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) {
form_error($form['name'], t('View name must be alphanumeric or underscores only.'));
}
if ($form_state['values']['name']) {
$view->name = $form_state['values']['name'];
}
$test = views_get_view($view->name);
if (!$form_state['values']['name_override']) {
if ($test && $test->type != t('Default')) {
form_set_error('', t('A view by that name already exists; please choose a different name'));
}
}
else {
if (!empty($test->vid)) {
$view->vid = $test->vid;
}
}
// Make sure base table gets set properly if it got moved.
$view->update();
$view->init_display();
$broken = FALSE;
// Bypass the validation of view pluigns/handlers if option is checked.
if (!$form_state['values']['bypass_validation']) {
// Make sure that all plugins and handlers needed by this view actually
// exist.
foreach ($view->display as $display) {
if (empty($display->handler) || !empty($display->handler->broken)) {
drupal_set_message(t('Display plugin @plugin is not available.', array(
'@plugin' => $display->display_plugin,
)), 'error');
$broken = TRUE;
continue;
}
$plugin = views_get_plugin('style', $display->handler
->get_option('style_plugin'));
if (!$plugin) {
drupal_set_message(t('Style plugin @plugin is not available.', array(
'@plugin' => $display->handler
->get_option('style_plugin'),
)), 'error');
$broken = TRUE;
}
elseif ($plugin->uses_row_plugin()) {
$plugin = views_get_plugin('row', $display->handler
->get_option('row_plugin'));
if (!$plugin) {
drupal_set_message(t('Row plugin @plugin is not available.', array(
'@plugin' => $display->handler
->get_option('row_plugin'),
)), 'error');
$broken = TRUE;
}
}
foreach (views_object_types() as $type => $info) {
$handlers = $display->handler
->get_handlers($type);
if ($handlers) {
foreach ($handlers as $handler) {
if ($handler->broken()) {
drupal_set_message(t('@type handler @table.@field is not available.', array(
'@type' => $info['stitle'],
'@table' => $handler->table,
'@field' => $handler->field,
)), 'error');
$broken = TRUE;
}
}
}
}
}
}
if ($broken) {
form_set_error('', t('Unable to import view.'));
}
$form_state['view'] =& $view;
}