pathValidator example

if ($uri_parts['path'][0] !== '/') {
        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. */
$this->setMockContainerService('menu.link_tree');
    $this->assertNotNull(\Drupal::menuTree());
  }

  /** * Tests the pathValidator() method. * * @covers ::pathValidator */
  public function testPathValidator() {
    $this->setMockContainerService('path.validator');
    $this->assertNotNull(\Drupal::pathValidator());
  }

  /** * Tests the accessManager() method. * * @covers ::accessManager */
  public function testAccessManager() {
    $this->setMockContainerService('access_manager');
    $this->assertNotNull(\Drupal::accessManager());
  }

  
Home | Imprint | This part of the site doesn't use cookies.