addOptionDefaults example

elseif (UrlHelper::isExternal($uri)) {
      // UrlHelper::isExternal() only returns true for safe protocols.       return $this->buildExternalUrl($uri$options$collect_bubbleable_metadata);
    }
    throw new \InvalidArgumentException("The URI '$uri' is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.");
  }

  /** * {@inheritdoc} */
  protected function buildExternalUrl($uri, array $options = []$collect_bubbleable_metadata = FALSE) {
    $this->addOptionDefaults($options);
    // Split off the query & fragment.     $parsed = UrlHelper::parse($uri);
    $uri = $parsed['path'];

    $parsed += ['query' => []];
    $options += ['query' => []];

    $options['query'] = NestedArray::mergeDeepArray([$parsed['query']$options['query']], TRUE);

    if ($parsed['fragment'] && !$options['fragment']) {
      $options['fragment'] = '#' . $parsed['fragment'];
    }
Home | Imprint | This part of the site doesn't use cookies.