Commit 748abf1b authored by catch's avatar catch

Issue #2163349 by dawehner: Cleanup a bunch of page callback related code in views.

parent 075521d0
......@@ -179,7 +179,7 @@ protected function getRoute($view_id, $display_id) {
// If this is to be a default tab, create the route for the parent path.
if ($this->isDefaultTabPath()) {
$bit = array_pop($bits);
if ($bit == '%views_arg' || empty($bits)) {
if (empty($bits)) {
$bits[] = $bit;
}
}
......@@ -284,18 +284,6 @@ public function executeHookMenu($callbacks) {
$this->view->initHandlers();
$view_arguments = $this->view->argument;
// Replace % with %views_arg for menu autoloading and add to the
// page arguments so the argument actually comes through.
foreach ($bits as $pos => $bit) {
if ($bit == '%') {
$argument = array_shift($view_arguments);
if (!empty($argument->options['specify_validation']) && $argument->options['validate']['type'] != 'none') {
$bits[$pos] = '%views_arg';
}
$page_arguments[] = $pos;
}
}
$path = implode('/', $bits);
$view_route_names = $this->state->get('views.view_route_names') ?: array();
......@@ -366,7 +354,7 @@ public function executeHookMenu($callbacks) {
// we can't do this if they tried to make the last path bit variable.
// @todo: We can validate this.
if ($bit != '%views_arg' && !empty($bits)) {
if (!empty($bits)) {
// Assign the route name to the parent route, not the default tab.
$default_route_name = $items[$path]['route_name'];
unset($items[$path]['route_name']);
......
......@@ -315,91 +315,6 @@ function views_menu_alter(&$callbacks) {
}
}
/**
* Helper function for menu loading. This will automatically be
* called in order to 'load' a views argument; primarily it
* will be used to perform validation.
*
* @param $value
* The actual value passed.
* @param $name
* The name of the view. This needs to be specified in the 'load function'
* of the menu entry.
* @param $display_id
* The display id that will be loaded for this menu item.
* @param $index
* The menu argument index. This counts from 1.
*/
function views_arg_load($value, $name, $display_id, $index) {
static $views = array();
// Make sure we haven't already loaded this views argument for a similar menu
// item elsewhere.
$key = $name . ':' . $display_id . ':' . $value . ':' . $index;
if (isset($views[$key])) {
return $views[$key];
}
if ($view = views_get_view($name)) {
$view->setDisplay($display_id);
$view->initHandlers();
$ids = array_keys($view->argument);
$indexes = array();
$path = explode('/', $view->getPath());
foreach ($path as $id => $piece) {
if ($piece == '%' && !empty($ids)) {
$indexes[$id] = array_shift($ids);
}
}
if (isset($indexes[$index])) {
if (isset($view->argument[$indexes[$index]])) {
$arg = $view->argument[$indexes[$index]]->validateMenuArgument($value) ? $value : FALSE;
$view->destroy();
// Store the output in case we load this same menu item again.
$views[$key] = $arg;
return $arg;
}
}
$view->destroy();
}
}
/**
* Page callback: Displays a page view, given a name and display id.
*
* @param $name
* The name of a view.
* @param $display_id
* The display id of a view.
*
* @return
* Either the HTML of a fully-executed view, or MENU_NOT_FOUND.
*/
function views_page($name, $display_id) {
$args = func_get_args();
// Remove $name and $display_id from the arguments.
array_shift($args);
array_shift($args);
// Load the view and render it.
if ($view = views_get_view($name)) {
if ($output = $view->executeDisplay($display_id, $args)) {
return $output;
}
else {
return array();
}
}
// Fallback if we get here no view was found.
return MENU_NOT_FOUND;
}
/**
* Implements hook_page_alter().
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment