本文整理汇总了PHP中Drupal\Core\Routing\UrlGeneratorInterface类的典型用法代码示例。如果您正苦于以下问题:PHP UrlGeneratorInterface类的具体用法?PHP UrlGeneratorInterface怎么用?PHP UrlGeneratorInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UrlGeneratorInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->eventDispatcher = $this->getMock(EventDispatcherInterface::class);
$this->entityManager = $this->getMock(EntityManagerInterface::class);
$this->urlGenerator = $this->getMock(UrlGeneratorInterface::class);
$this->urlGenerator->expects($this->any())->method('generateFromRoute')->willReturn('http://example.com');
$this->stringTranslation = $this->getStringTranslationStub();
$this->payment = $this->getMock(PaymentInterface::class);
$this->sut = new PaymentReference([], 'payment_reference', [], $this->eventDispatcher, $this->urlGenerator, $this->entityManager, $this->stringTranslation);
$this->sut->setPayment($this->payment);
}
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:14,代码来源:PaymentReferenceTest.php
示例2: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$this->urlGenerator->expects($this->any())->method('generateFromPath')->will($this->returnArgument(0));
$this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
$container = new ContainerBuilder();
$container->set('router', $this->router);
$container->set('url_generator', $this->urlGenerator);
\Drupal::setContainer($container);
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:ExternalUrlTest.php
示例3: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$map = array();
$map[] = array('view.frontpage.page_1', array(), array(), '/node');
$map[] = array('node_view', array('node' => '1'), array(), '/node/1');
$map[] = array('node_edit', array('node' => '2'), array(), '/node/2/edit');
$this->map = $map;
$this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$this->urlGenerator->expects($this->any())->method('generateFromRoute')->will($this->returnValueMap($this->map));
$this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
$container = new ContainerBuilder();
$container->set('router', $this->router);
$container->set('url_generator', $this->urlGenerator);
\Drupal::setContainer($container);
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:19,代码来源:UrlTest.php
示例4: createHtmlFragment
/**
* Converts a render array into an HtmlFragment object.
*
* @param array|string $page_content
* The page content area to display.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @return \Drupal\Core\Page\HtmlPage
* A page object.
*/
protected function createHtmlFragment($page_content, Request $request)
{
// Allow controllers to return a HtmlFragment or a Response object directly.
if ($page_content instanceof HtmlFragment || $page_content instanceof Response) {
return $page_content;
}
if (!is_array($page_content)) {
$page_content = array('main' => array('#markup' => $page_content));
}
$content = $this->drupalRender($page_content);
$cache = !empty($page_content['#cache']['tags']) ? array('tags' => $page_content['#cache']['tags']) : array();
$fragment = new HtmlFragment($content, $cache);
// A title defined in the return always wins.
if (isset($page_content['#title'])) {
$fragment->setTitle($page_content['#title'], Title::FILTER_XSS_ADMIN);
} else {
if ($route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
$fragment->setTitle($this->titleResolver->getTitle($request, $route), Title::PASS_THROUGH);
}
}
// Add feed links from the page content.
$attached = drupal_render_collect_attached($page_content, TRUE);
if (!empty($attached['drupal_add_feed'])) {
foreach ($attached['drupal_add_feed'] as $feed) {
$feed_link = new FeedLinkElement($feed[1], $this->urlGenerator->generateFromPath($feed[0]));
$fragment->addLinkElement($feed_link);
}
}
return $fragment;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:41,代码来源:HtmlControllerBase.php
示例5: render
/**
* {@inheritdoc}
*/
public function render(array $render_array)
{
$content = $this->drupalRenderRoot($render_array);
if (!empty($render_array)) {
drupal_process_attached($render_array);
}
$cache = !empty($render_array['#cache']['tags']) ? ['tags' => $render_array['#cache']['tags']] : [];
$fragment = new HtmlFragment($content, $cache);
if (isset($render_array['#title'])) {
$fragment->setTitle($render_array['#title'], Title::FILTER_XSS_ADMIN);
}
$attached = isset($render_array['#attached']) ? $render_array['#attached'] : [];
$attached += ['feed' => [], 'html_head' => [], 'html_head_link' => []];
// Add feed links from the page content.
foreach ($attached['feed'] as $feed) {
$fragment->addLinkElement(new FeedLinkElement($feed[1], $this->urlGenerator->generateFromPath($feed[0])));
}
// Add generic links from the page content.
foreach ($attached['html_head_link'] as $link) {
$fragment->addLinkElement(new LinkElement($this->urlGenerator->generateFromPath($link[0]['href']), $link[0]['rel']));
}
// @todo Also transfer the contents of "_drupal_add_html_head" once
// https://www.drupal.org/node/2296951 lands.
// @todo Transfer CSS and JS over to the fragment once those are supported
// on the fragment object.
return $fragment;
}
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:30,代码来源:RenderHtmlRenderer.php
示例6: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = NULL)
{
if ($this->translation instanceof TranslationManagerWrapper) {
/** \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper $this->translation */
$this->data['translations']['translated'] = $this->translation->getTranslated();
$this->data['translations']['untranslated'] = $this->translation->getUntranslated();
}
$data['user_interface_translations_path'] = $this->urlGenerator->generateFromRoute('locale.translate_page');
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:12,代码来源:TranslationsDataCollector.php
示例7: execute
/**
* {@inheritdoc}
*/
public function execute($object = NULL)
{
$url = $this->urlGenerator->generateFromPath($this->configuration['url'], array('absolute' => TRUE));
$response = new RedirectResponse($url);
$listener = function ($event) use($response) {
$event->setResponse($response);
};
// Add the listener to the event dispatcher.
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener);
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:13,代码来源:GotoAction.php
示例8: setupUrlGenerator
protected function setupUrlGenerator()
{
$this->urlGenerator->expects($this->any())->method('generateFromRoute')->willReturnCallback(function ($route, $parameters, $options) {
$query_string = '';
if (!empty($options['query'])) {
$query_string = '?' . $options['query'];
}
return '/current-path' . $query_string;
});
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:RedirectDestinationTest.php
示例9: testProcessOutbound
/**
* Tests the output process.
*/
public function testProcessOutbound()
{
$expected_cacheability = (new BubbleableMetadata())->addCacheContexts(['route'])->setCacheMaxAge(Cache::PERMANENT);
$request_stack = \Drupal::requestStack();
/** @var \Symfony\Component\Routing\RequestContext $request_context */
$request_context = \Drupal::service('router.request_context');
// Test request with subdir on homepage.
$server = ['SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
$request = Request::create('/subdir/', 'GET', [], [], [], $server);
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>');
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
$request_stack->push($request);
$request_context->fromRequest($request);
$url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/subdir/');
$this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
// Test request with subdir on other page.
$server = ['SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
$request = Request::create('/subdir/node/add', 'GET', [], [], [], $server);
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'node.add');
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/node/add'));
$request_stack->push($request);
$request_context->fromRequest($request);
$url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/subdir/node/add');
$this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
// Test request without subdir on the homepage.
$server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
$request = Request::create('/', 'GET', [], [], [], $server);
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>');
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
$request_stack->push($request);
$request_context->fromRequest($request);
$url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/');
$this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
// Test request without subdir on other page.
$server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
$request = Request::create('/node/add', 'GET', [], [], [], $server);
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'node.add');
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/node/add'));
$request_stack->push($request);
$request_context->fromRequest($request);
$url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/node/add');
$this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
// Test request without a found route. This happens for example on an
// not found exception page.
$server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
$request = Request::create('/invalid-path', 'GET', [], [], [], $server);
$request_stack->push($request);
$request_context->fromRequest($request);
// In case we have no routing, the current route should point to the front,
// and the cacheability does not depend on the 'route' cache context, since
// no route was involved at all: this is fallback behavior.
$url = GeneratedUrl::createFromObject((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT))->setGeneratedUrl('/');
$this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:57,代码来源:RouteProcessorCurrentIntegrationTest.php
示例10: testExecute
/**
* @covers ::execute
*/
public function testExecute()
{
$url = $this->randomMachineName();
$currency = $this->getMock(CurrencyInterface::class);
$currency->expects($this->once())->method('enable');
$currency->expects($this->once())->method('save');
$this->urlGenerator->expects($this->once())->method('generateFromRoute')->with('entity.currency.collection')->willReturn($url);
$response = $this->sut->execute($currency);
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertSame($url, $response->getTargetUrl());
}
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:14,代码来源:EnableCurrencyTest.php
示例11: injectToolbar
/**
* @param \Symfony\Component\HttpFoundation\Response $response
*/
protected function injectToolbar(Response $response)
{
$content = $response->getContent();
$pos = mb_strripos($content, '</body>');
if (FALSE !== $pos) {
if ($token = $response->headers->get('X-Debug-Token')) {
$loader = ['#theme' => 'webprofiler_loader', '#token' => $token, '#profiler_url' => $this->urlGenerator->generate('webprofiler.toolbar', ['profile' => $token])];
$content = mb_substr($content, 0, $pos) . $this->renderer->renderRoot($loader) . mb_substr($content, $pos);
$response->setContent($content);
}
}
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:15,代码来源:WebprofilerEventSubscriber.php
示例12: listAttribute
/**
* {@inheritdoc}
*/
public function listAttribute($content)
{
$this->crawler->addContent($content);
$this->links = array();
$this->crawler->filter('a')->each(function (HtmlPageCrawler $anchor, $uri) {
$href = $anchor->attr('href');
// @todo deprecated method.
$this->links[] = $this->urlGenerator->generateFromPath($href, array('absolute' => TRUE));
});
$this->crawler->remove();
return implode(',', $this->links);
}
开发者ID:gerbreown1,项目名称:calvaryfree,代码行数:15,代码来源:InlineLinkExtractor.php
示例13: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$config = $this->config('ckeditor_media_embed.settings');
$form['embed_provider'] = array('#type' => 'textfield', '#title' => $this->t('Provider URL'), '#default_value' => $config->get('embed_provider'), '#description' => $this->t('A template for the URL of the provider endpoint.
This URL will be queried for each resource to be embedded. By default CKEditor uses the Iframely service.<br />
<strong>Example</strong> <code>//example.com/api/oembed-proxy?resource-url={url}&callback={callback}</code><br />
<strong>Default</strong> <code>//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}</code><br />
'));
if ($this->moduleHandler->moduleExists('help')) {
$form['embed_provider']['#description'] .= $this->t('Check out the <a href=":help">help</a> page for more information.<br />', array(':help' => $this->urlGenerator->generateFromRoute('help.page', array('name' => 'ckeditor_media_embed'))));
}
return parent::buildForm($form, $form_state);
}
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:16,代码来源:CKEditorMediaEmbedSettingsForm.php
示例14: get
/**
* {@inheritdoc}
*/
public function get()
{
if (!isset($this->destination)) {
$query = $this->requestStack->getCurrentRequest()->query;
if (UrlHelper::isExternal($query->get('destination'))) {
$this->destination = '/';
} elseif ($query->has('destination')) {
$this->destination = $query->get('destination');
} else {
$this->destination = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => UrlHelper::buildQuery(UrlHelper::filterQueryParameters($query->all()))]);
}
}
return $this->destination;
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:RedirectDestination.php
示例15: render
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['#empty'] = t('No eform types available. <a href="@link">Add EForm type</a>.', array(
'@link' => $this->urlGenerator->generateFromRoute('eform.type_add'),
));
return $build;
}
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:10,代码来源:EFormTypeListBuilder.php
示例16: render
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['#empty'] = $this->t('There are currently no blocktabs. <a href=":url">Add a new one</a>.', array(
':url' => $this->urlGenerator->generateFromRoute('blocktabs.add'),
));
return $build;
}
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:10,代码来源:BlocktabsListBuilder.php
示例17: onKernelRequestMaintenance
/**
* Returns the site maintenance page if the site is offline.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event to process.
*/
public function onKernelRequestMaintenance(GetResponseEvent $event)
{
$route_match = RouteMatch::createFromRequest($event->getRequest());
if ($this->maintenanceMode->applies($route_match)) {
if (!$this->maintenanceMode->exempt($this->account)) {
// Deliver the 503 page if the site is in maintenance mode and the
// logged in user is not allowed to bypass it.
drupal_maintenance_theme();
$content = Xss::filterAdmin(String::format($this->config->get('system.maintenance')->get('message'), array('@site' => $this->config->get('system.site')->get('name'))));
// @todo Break the dependency on DefaultHtmlPageRenderer, see:
// https://www.drupal.org/node/2295609
$content = DefaultHtmlPageRenderer::renderPage($content, $this->t('Site under maintenance'));
$response = new Response('Service unavailable', 503);
$response->setContent($content);
$event->setResponse($response);
} else {
// Display a message if the logged in user has access to the site in
// maintenance mode. However, suppress it on the maintenance mode
// settings page.
if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
if ($this->account->hasPermission('administer site configuration')) {
$this->drupalSetMessage($this->t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE);
} else {
$this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
}
}
}
}
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:35,代码来源:MaintenanceModeSubscriber.php
示例18: assertRedirectedToFrontPageOnHandle
/**
* Assert user redirected to homepage when controller invoked.
*/
private function assertRedirectedToFrontPageOnHandle()
{
// URL Generator will generate a path to the homepage.
$this->urlGenerator->expects($this->once())->method('generate')->with('<front>')->will($this->returnValue('http://example.com/front'));
$response = $this->serviceController->handle();
$this->assertTrue($response->isRedirect('http://example.com/front'));
}
开发者ID:pulibrary,项目名称:recap,代码行数:10,代码来源:ServiceControllerTest.php
示例19: render
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['table']['#empty'] = t('No crop types available. <a href="@link">Add crop type</a>.', [
'@link' => $this->urlGenerator->generateFromRoute('crop.type_add'),
]);
return $build;
}
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:10,代码来源:CropTypeListBuilder.php
示例20: onKernelRequestMaintenance
/**
* Returns the site maintenance page if the site is offline.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event to process.
*/
public function onKernelRequestMaintenance(GetResponseEvent $event)
{
$request = $event->getRequest();
$route_match = RouteMatch::createFromRequest($request);
if ($this->maintenanceMode->applies($route_match)) {
// Don't cache maintenance mode pages.
\Drupal::service('page_cache_kill_switch')->trigger();
if (!$this->maintenanceMode->exempt($this->account)) {
// Deliver the 503 page if the site is in maintenance mode and the
// logged in user is not allowed to bypass it.
// If the request format is not 'html' then show default maintenance
// mode page else show a text/plain page with maintenance message.
if ($request->getRequestFormat() !== 'html') {
$response = new Response($this->getSiteMaintenanceMessage(), 503, array('Content-Type' => 'text/plain'));
$event->setResponse($response);
return;
}
drupal_maintenance_theme();
$response = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $this->getSiteMaintenanceMessage()], $this->t('Site under maintenance'), 'maintenance_page');
$response->setStatusCode(503);
$event->setResponse($response);
} else {
// Display a message if the logged in user has access to the site in
// maintenance mode. However, suppress it on the maintenance mode
// settings page.
if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
if ($this->account->hasPermission('administer site configuration')) {
$this->drupalSetMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', array(':url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE);
} else {
$this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
}
}
}
}
}
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:41,代码来源:MaintenanceModeSubscriber.php
注:本文中的Drupal\Core\Routing\UrlGeneratorInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论