public function AlphaPagination::getUrl in Views Alpha Pagination 7.2
Retrieves the URL for the current view.
Note: this follows very similarly to \view::get_url to process arguments, however it is in fact severely modified to account for characters appended by this module.
Return value
string The URL for the view or current_path().
1 call to AlphaPagination::getUrl()
- AlphaPagination::getTokens in src/
AlphaPagination.php - Provides the token data that is passed when during replacement.
File
- src/
AlphaPagination.php, line 621
Class
- AlphaPagination
- A base views handler for alpha pagination.
Code
public function getUrl() {
static $url;
if (!isset($url)) {
if (!empty($this->handler->view->override_url)) {
return $this->handler->view->override_url;
}
$path = $this->handler->view
->get_path();
$args = $this->handler->view->args;
// Exclude arguments that were computed, not passed on the URL.
$position = 0;
if (!empty($this->handler->view->argument)) {
foreach ($this->handler->view->argument as $argument_id => $argument) {
if (!empty($argument->options['default_argument_skip_url'])) {
unset($args[$position]);
}
$position++;
}
}
// Don't bother working if there's nothing to do:
if (empty($path) || empty($args) && strpos($path, '%') === FALSE) {
$path = current_path();
$pieces = explode('/', $path);
if (array_key_exists(end($pieces), $this
->getCharacters())) {
array_pop($pieces);
}
$url = implode('/', $pieces);
return $url;
}
$pieces = [];
$argument_keys = isset($this->handler->view->argument) ? array_keys($this->handler->view->argument) : [];
$id = current($argument_keys);
foreach (explode('/', $path) as $piece) {
if ($piece != '%') {
$pieces[] = $piece;
}
else {
if (empty($args)) {
// Try to never put % in a url; use the wildcard instead.
if ($id && !empty($this->handler->view->argument[$id]->options['exception']['value'])) {
$pieces[] = $this->handler->view->argument[$id]->options['exception']['value'];
}
else {
$pieces[] = '*';
// gotta put something if there just isn't one.
}
}
else {
$pieces[] = array_shift($args);
}
if ($id) {
$id = next($argument_keys);
}
}
}
// Just return the computed pieces, don't merge any extra remaining args.
$url = implode('/', $pieces);
}
return $url;
}