当前位置: 首页>>代码示例>>PHP>>正文


PHP Url::getRouteName方法代码示例

本文整理汇总了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);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:23,代码来源:FieldPluginBaseTest.php

示例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));
     }
 }
开发者ID:Progressable,项目名称:openway8,代码行数:23,代码来源:GlobalredirectSubscriber.php

示例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'));
     }
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:26,代码来源:EntityUrlTest.php

示例4: testGetRouteName

 /**
  * Tests the getRouteName() method.
  *
  * @depends testCreateFromPath
  *
  * @expectedException \UnexpectedValueException
  *
  * @covers ::getRouteName()
  */
 public function testGetRouteName(Url $url)
 {
     $url->getRouteName();
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:13,代码来源:ExternalUrlTest.php

示例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);
     }
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:24,代码来源:RedirectRequestSubscriber.php


注:本文中的Drupal\Core\Url::getRouteName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。