ViewExecutable::hasUrl

public ViewExecutable::hasUrl($args = NULL, $display_id = NULL)

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 1877

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.