function ViewExecutable::hasUrl

Same name in other branches
  1. 9 core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::hasUrl()
  2. 8.9.x core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::hasUrl()
  3. 11.x 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 TRUE if the current display has a valid route available, FALSE otherwise.

File

core/modules/views/src/ViewExecutable.php, line 1950

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

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.
    try {
        $this->routeProvider
            ->getRouteByName($display_handler->getRouteName());
    } catch (RouteNotFoundException $e) {
        return FALSE;
    }
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.