diff --git a/admin_views.module b/admin_views.module index 8aace86..84fcb25 100644 --- a/admin_views.module +++ b/admin_views.module @@ -18,25 +18,29 @@ function admin_views_views_api() { * Implements hook_menu_alter(). */ function admin_views_menu_alter(&$items) { - // Check for duplicate paths and unset additional access arguments. - $duplicate_paths = array(); - foreach($items as $path => $item) { - if (isset($item['page callback']) && $item['page callback'] == 'views_page') { - if (isset($item['access callback']) && $item['access callback'] == 'user_access' && count($item['access arguments']) > 1) { - $duplicate_paths[] = $path; - // Remove all extra access arguments so only one view is accessible. - foreach ($item['access arguments'] as $key => $value) { - if ($key > 0) { - unset($items[$path]['access arguments'][$key]); - } + // Build an array of system paths from Views displays. + $system_paths = array(); + foreach (views_get_all_views() as $view) { + if (!$view->disabled) { + foreach ($view->display as $settings) { + if (isset($settings->display_plugin) && $settings->display_plugin == 'system') { + $system_paths[] = $settings->display_options['path']; } } } } - // Present error message to user notifying that views edits are required. - if (!empty($duplicate_paths)) { + // Filter system paths for duplicates. + $duplicate_paths = array_filter(array_count_values($system_paths), function($v) { return $v > 1; }); + // Remove extra menu access arguments from duplicate paths. + $message_paths = array(); + foreach ($duplicate_paths as $path => $path_count) { + $message_paths[] = $path; + array_splice($items[$path]['access arguments'], 1); + } + // Present error message notifying that views edits are required. + if (!empty($message_paths)) { $message = t('The following system paths exist on multiple views: !paths. Please disable or delete unneeded views. Access to the conflicting views will be limited until resolved.', - array('!paths' => implode(', ', $duplicate_paths))); + array('!paths' => implode(', ', $message_paths))); drupal_set_message($message, 'error'); } }