You are here

public function LinkedFieldManager::buildDestinationUrl in Linked Field 8

Build the final destination URL.

Parameters

string $destination: The destination.

Return value

false|string Either FALSE or the destination URL.

Overrides LinkedFieldManagerInterface::buildDestinationUrl

File

src/LinkedFieldManager.php, line 166

Class

LinkedFieldManager
Provides helper methods for client related functionalities.

Namespace

Drupal\linked_field

Code

public function buildDestinationUrl($destination) {
  $parsed_url = parse_url($destination);

  // Try to fix internal URLs by prefixing them with "internal:/".
  if (!isset($parsed_url['scheme'])) {

    // Let's support "/node/1" and "node/1" here.
    $slash = $destination[0] == '/' ? '' : '/';
    $destination = 'internal:' . $slash . $destination;
  }
  try {
    $url = Url::fromUri($destination);
    $destination_url = $url
      ->setAbsolute()
      ->toString();
    return $destination_url;
  } catch (\Exception $e) {
    return FALSE;
  }
}