diff --git a/admin_views.module b/admin_views.module index 328c877..22dec8d 100644 --- a/admin_views.module +++ b/admin_views.module @@ -26,24 +26,19 @@ function admin_views_form_views_ui_edit_form_alter(&$form, &$form_state) { */ function _admin_views_form_views_ui_edit_form_validate(&$form, &$form_state) { if (isset($form_state['view'])) { - $system_views = array(); - // Check if current view has system view displays. - foreach ($form_state['view']->display as $display => $settings) { - if (isset($settings->display_plugin) && $settings->display_plugin == 'system') { - $system_views[] = array( - 'path' => $settings->display_options['path'], - 'name' => $form_state['view']->name, - 'display' => $display, - ); - break; - } - } - // If there are system view displays, check if any duplicates. - if (!empty($system_views)) { + // Retrieve system paths on the current view. + $system_paths = admin_views_system_paths($form_state['view']); + // If system paths exist, check if any duplicates. + if (!empty($system_paths)) { $duplicate_paths = array(); - foreach ($system_views as $system_view) { - if (admin_views_duplicate_path($system_view)) { - $duplicate_paths[] = $system_view['path']; + foreach ($system_paths as $path => $path_views) { + foreach ($path_views as $path_view) { + foreach ($path_view as $view_name => $view_display) { + $system_view[$path] = array($view_name => $view_display); + if (admin_views_duplicate_path($system_view)) { + $duplicate_paths[] = $path; + } + } } } // If any duplicates, display error message. @@ -58,17 +53,27 @@ function _admin_views_form_views_ui_edit_form_validate(&$form, &$form_state) { /** * Paths for enabled system views. * + * @param object $view + * (optional) A view to be checked for system view displays. If not + * included, all views are checked. + * * @return array - * An array of system paths, including view name and view display. + * An array of system paths, including view name and view display. */ -function admin_views_system_paths() { +function admin_views_system_paths($view = NULL) { $system_paths = array(); - foreach (views_get_all_views() as $view) { + if ($view == NULL) { + $views = views_get_all_views(); + } + else { + $views[] = $view; + } + foreach ($views as $view) { if ($view->disabled) { continue; } foreach ($view->display as $display => $settings) { - if (isset($settings->display_plugin) && $settings->display_plugin == 'system') { + if (isset($settings->display_plugin) && $settings->display_plugin == 'system' && isset($settings->display_options['path'])) { $system_paths[$settings->display_options['path']][] = array($view->name => $display); } } @@ -79,21 +84,24 @@ function admin_views_system_paths() { /** * Determine if there are duplicate views system paths. * - * @param array $system_view + * @param array $view * Array including a system path, and the view name and display where it * is located. * * @return boolean * Duplicate path exists other than current view name/display combination. */ -function admin_views_duplicate_path($system_view) { +function admin_views_duplicate_path($view) { $system_paths = admin_views_system_paths(); - if (!isset($system_paths[$system_view['path']])) { + $view_path = key($view); + if (!isset($system_paths[$view_path])) { return FALSE; } - foreach ($system_paths[$system_view['path']] as $item => $views) { - foreach ($views as $view_name => $view_display) { - if (!($view_name == $system_view['name'] && $view_display == $system_view['display'])) { + $view_name = key($view[$view_path]); + $view_display = $view[$view_path][$view_name]; + foreach ($system_paths[$view_path] as $system_views) { + foreach ($system_views as $system_view_name => $system_view_display) { + if (!($system_view_name == $view_name && $system_view_display == $view_display)) { return TRUE; } } diff --git a/plugins/views_plugin_display_system.inc b/plugins/views_plugin_display_system.inc index ec5084f..41d1181 100644 --- a/plugins/views_plugin_display_system.inc +++ b/plugins/views_plugin_display_system.inc @@ -132,11 +132,7 @@ class views_plugin_display_system extends views_plugin_display { // Automatically remove '/' from path. $form_state['values']['path'] = trim($form_state['values']['path'], '/'); - $system_view = array( - 'path' => $form_state['values']['path'], - 'name' => $this->view->name, - 'display' => $this->view->current_display, - ); + $system_view[$form_state['values']['path']] = array($this->view->name => $this->view->current_display); if (admin_views_duplicate_path($system_view)) { form_error($form['path'], t('Already used by another system view. Enter a different path.')); }