本文整理汇总了PHP中Drupal\Core\Url::getRouteName方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::getRouteName方法的具体用法?PHP Url::getRouteName怎么用?PHP Url::getRouteName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Url
的用法示例。
在下文中一共展示了Url::getRouteName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRenderAsLinkWithUrlAndOptions
/**
* Tests link rendering with a URL and options.
*
* @dataProvider providerTestRenderAsLinkWithUrlAndOptions
* @covers ::renderAsLink
*/
public function testRenderAsLinkWithUrlAndOptions(Url $url, $alter, Url $expected_url, $url_path, Url $expected_link_url, $link_html, $final_html = NULL)
{
$alter += ['make_link' => TRUE, 'url' => $url];
$final_html = isset($final_html) ? $final_html : $link_html;
$this->setUpUrlIntegrationServices();
$this->setupDisplayWithEmptyArgumentsAndFields();
$field = $this->setupTestField(['alter' => $alter]);
$field->field_alias = 'key';
$row = new ResultRow(['key' => 'value']);
$expected_url->setOptions($expected_url->getOptions() + $this->defaultUrlOptions);
$expected_link_url->setUrlGenerator($this->urlGenerator);
$expected_url_options = $expected_url->getOptions();
unset($expected_url_options['attributes']);
$this->urlGenerator->expects($this->once())->method('generateFromRoute')->with($expected_url->getRouteName(), $expected_url->getRouteParameters(), $expected_url_options)->willReturn($url_path);
$result = $field->advancedRender($row);
$this->assertEquals($final_html, $result);
}
示例2: setResponse
/**
* Prior to set the response it check if we can redirect.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event object.
* @param \Drupal\Core\Url $url
* The Url where we want to redirect.
*/
protected function setResponse(GetResponseEvent $event, Url $url)
{
$request = $event->getRequest();
$this->context->fromRequest($request);
parse_str($request->getQueryString(), $query);
$url->setOption('query', $query);
$url->setAbsolute(TRUE);
// We can only check access for routed URLs.
if (!$url->isRouted() || $this->redirectChecker->canRedirect($url->getRouteName(), $request)) {
// Add the 'rendered' cache tag, so that we can invalidate all responses
// when settings are changed.
$headers = ['X-Drupal-Cache-Tags' => 'rendered'];
$event->setResponse(new RedirectResponse($url->toString(), 301, $headers));
}
}
示例3: assertUrl
/**
* Asserts that a given URL object matches the expectations.
*
* @param string $expected_route_name
* The expected route name of the generated URL.
* @param array $expected_route_parameters
* The expected route parameters of the generated URL.
* @param \Drupal\Core\Entity\Entity|\PHPUnit_Framework_MockObject_MockObject $entity
* The entity that is expected to be set as a URL option.
* @param bool $has_language
* Whether or not the URL is expected to have a language option.
* @param \Drupal\Core\Url $url
* The URL option to make the assertions on.
*/
protected function assertUrl($expected_route_name, array $expected_route_parameters, $entity, $has_language, Url $url)
{
$this->assertEquals($expected_route_name, $url->getRouteName());
$this->assertEquals($expected_route_parameters, $url->getRouteParameters());
$this->assertEquals($this->entityTypeId, $url->getOption('entity_type'));
$this->assertEquals($entity, $url->getOption('entity'));
if ($has_language) {
$this->assertEquals($this->langcode, $url->getOption('language')->getId());
} else {
$this->assertNull($url->getOption('language'));
}
}
示例4: testGetRouteName
/**
* Tests the getRouteName() method.
*
* @depends testCreateFromPath
*
* @expectedException \UnexpectedValueException
*
* @covers ::getRouteName()
*/
public function testGetRouteName(Url $url)
{
$url->getRouteName();
}
示例5: setResponse
/**
* Prior to set the response it check if we can redirect.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event object.
* @param \Drupal\Core\Url $url
* The Url where we want to redirect.
*/
protected function setResponse(GetResponseEvent $event, Url $url)
{
$request = $event->getRequest();
$this->context->fromRequest($request);
parse_str($request->getQueryString(), $query);
$url->setOption('query', $query);
$url->setAbsolute(TRUE);
// We can only check access for routed URLs.
if (!$url->isRouted() || $this->checker->canRedirect($request, $url->getRouteName())) {
// Add the 'rendered' cache tag, so that we can invalidate all responses
// when settings are changed.
$response = new TrustedRedirectResponse($url->toString(), 301);
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray([])->addCacheTags(['rendered']));
$event->setResponse($response);
}
}