public function ViewExecutable::hasUrl in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::hasUrl()
Determines whether you can link to the view or a particular display.
Some displays (e.g. block displays) do not have their own route, but may optionally provide a link to another display that does have a route.
Parameters
array $args: (optional) The arguments.
string $display_id: (optional) The display ID. The current display will be used by default.
Return value
bool
File
- core/
modules/ views/ src/ ViewExecutable.php, line 1757 - Contains \Drupal\views\ViewExecutable.
Class
- ViewExecutable
- Represents a view as a whole.
Namespace
Drupal\viewsCode
public function hasUrl($args = NULL, $display_id = NULL) {
if (!empty($this->override_url)) {
return TRUE;
}
// If the display has a valid route available (either its own or for a
// linked display), then we can provide a URL for it.
$display_handler = $this->displayHandlers
->get($display_id ?: $this->current_display)
->getRoutedDisplay();
if (!$display_handler instanceof DisplayRouterInterface) {
return FALSE;
}
// Look up the route name to make sure it exists. The name may exist, but
// not be available yet in some instances when editing a view and doing
// a live preview.
$provider = \Drupal::service('router.route_provider');
try {
$provider
->getRouteByName($display_handler
->getRouteName());
} catch (RouteNotFoundException $e) {
return FALSE;
}
return TRUE;
}