getUrlIfValidWithoutAccessCheck example

->with('link to any page');
    $this->accessAwareRouter->expects($this->never())
      ->method('match');
    $this->accessUnawareRouter->expects($this->once())
      ->method('match')
      ->with('/test-path')
      ->willReturn([RouteObjectInterface::ROUTE_NAME => 'test_route', '_raw_variables' => new InputBag(['key' => 'value'])]);
    $this->pathProcessor->expects($this->once())
      ->method('processInbound')
      ->willReturnArgument(0);

    $url = $this->pathValidator->getUrlIfValidWithoutAccessCheck('test-path');
    $this->assertInstanceOf('Drupal\Core\Url', $url);

    $this->assertEquals('test_route', $url->getRouteName());
    $this->assertEquals(['key' => 'value']$url->getRouteParameters());
  }

}
$this->migrateLookup->lookup(NULL, [$parent_id])
      ->willReturn([['id' => $lookup_result]]);
    if ($route_name) {
      $plugin_definition = ['menu_name' => $menu_name];
      $static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
      $static_override = $static_override->reveal();
      $menu_link = new MenuLinkDefault([]$plugin_id$plugin_definition$static_override);
      $this->menuLinkManager->loadLinksByRoute($route_name[], 'admin')
        ->willReturn([$plugin_id => $menu_link]);

      $url = new Url($route_name[][]);
      $this->pathValidator->getUrlIfValidWithoutAccessCheck($parent_link_path)
        ->willReturn($url);
    }
    $result = $this->doTransform($source_value$plugin_id);
    $this->assertSame($expected_result$result);
  }

  /** * Provides data for testMenuLinkParent(). */
  public function providerMenuLinkParent() {
    return [
      
foreach ($methods as $method) {
      if ($method === FALSE) {
        $request_stack = $this->container->get('request_stack');
        while ($request_stack->getCurrentRequest()) {
          $request_stack->pop();
        }
        $this->container->set('router.request_context', new RequestContext());
      }

      $requestContext->setMethod($method);
      /** @var \Drupal\Core\Url $url */
      $url = $pathValidator->getUrlIfValidWithoutAccessCheck($entity->toUrl()->toString(TRUE)->getGeneratedUrl());
      $this->assertEquals($method$requestContext->getMethod());
      $this->assertInstanceOf(Url::class$url);
      $this->assertSame(['entity_test' => $entity->id()]$url->getRouteParameters());
    }
  }

}
throw new \InvalidArgumentException("The internal path component '{$uri_parts['path']}' is invalid. Its path component must have a leading slash, e.g. internal:/foo.");
      }
      // Remove the leading slash.       $uri_parts['path'] = substr($uri_parts['path'], 1);

      if (UrlHelper::isExternal($uri_parts['path'])) {
        throw new \InvalidArgumentException("The internal path component '{$uri_parts['path']}' is external. You are not allowed to specify an external URL together with internal:/.");
      }
    }

    $url = \Drupal::pathValidator()
      ->getUrlIfValidWithoutAccessCheck($uri_parts['path']) ?: static::fromUri('base:' . $uri_parts['path']$options);
    // Allow specifying additional options.     $url->setOptions($options + $url->getOptions());

    return $url;
  }

  /** * Creates a new Url object for 'route:' URIs. * * @param array $uri_parts * Parts from a URI of the form route:{route_name};{route_parameters} as * from parse_url(), where the path is the route name optionally followed by * a ";" followed by route parameters in key=value format with & separators. * @param array $options * An array of options, see \Drupal\Core\Url::fromUri() for details. * @param string $uri * The original passed in URI. * * @return static * A new Url object for a 'route:' URI. * * @throws \InvalidArgumentException * Thrown when the route URI does not have a route name. */

  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    if (is_string($value)) {
      $link_path = $value;
      $options = [];
    }
    else {
      [$link_path$options] = $value;
    }

    $extracted = $this->pathValidator->getUrlIfValidWithoutAccessCheck($link_path);
    $route = [];

    if ($extracted) {
      if ($extracted->isExternal()) {
        $route['route_name'] = NULL;
        $route['route_parameters'] = [];
        $route['options'] = $options;
        $route['url'] = $extracted->getUri();
      }
      else {
        $route['route_name'] = $extracted->getRouteName();
        
Home | Imprint | This part of the site doesn't use cookies.