Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ViewExecutable.php

function 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) {
        return FALSE;
    }
    return TRUE;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal