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


PHP UrlGeneratorInterface::generateFromPath方法代码示例

本文整理汇总了PHP中Drupal\Core\Routing\UrlGeneratorInterface::generateFromPath方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlGeneratorInterface::generateFromPath方法的具体用法?PHP UrlGeneratorInterface::generateFromPath怎么用?PHP UrlGeneratorInterface::generateFromPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Routing\UrlGeneratorInterface的用法示例。


在下文中一共展示了UrlGeneratorInterface::generateFromPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: generateFromPath

 /**
  * {@inheritdoc}
  */
 public function generateFromPath($path = NULL, $options = array(), $collect_bubbleable_metadata = FALSE)
 {
     $generated_url = $this->urlGenerator->generateFromPath($path, $options, TRUE);
     if (!$collect_bubbleable_metadata) {
         $this->bubble($generated_url, $options);
     }
     return $collect_bubbleable_metadata ? $generated_url : $generated_url->getGeneratedUrl();
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:11,代码来源:MetadataBubblingUrlGenerator.php

示例6: getUrlFromPath

 /**
  * Generates an absolute URL given a path.
  *
  * @param string $path
  *   The path.
  * @param array $options
  *   (optional) An associative array of additional options. The 'absolute'
  *   option is forced to be TRUE.
  *
  * @return string
  *   The generated absolute URL for the given path.
  *
  * @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 8.0.0.
  */
 public function getUrlFromPath($path, $options = array())
 {
     // Generate URL.
     $options['absolute'] = TRUE;
     $generated_url = $this->urlGenerator->generateFromPath($path, $options, TRUE);
     // Return as render array, so we can bubble the bubbleable metadata.
     $build = ['#markup' => $generated_url->getGeneratedUrl()];
     $generated_url->applyTo($build);
     return $build;
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:24,代码来源:TwigExtension.php

示例7: checkRedirectUrl

 /**
  * Allows manipulation of the response object when performing a redirect.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The Event to process.
  */
 public function checkRedirectUrl(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($response instanceof RedirectResponse) {
         $options = array();
         $request = $event->getRequest();
         $destination = $request->query->get('destination');
         // A destination from \Drupal::request()->query always overrides the
         // current RedirectResponse. We do not allow absolute URLs to be passed
         // via \Drupal::request()->query, as this can be an attack vector, with
         // the following exception:
         // - Absolute URLs that point to this site (i.e. same base URL and
         //   base path) are allowed.
         if ($destination) {
             if (!UrlHelper::isExternal($destination)) {
                 // The destination query parameter can be a relative URL in the sense
                 // of not including the scheme and host, but its path is expected to
                 // be absolute (start with a '/'). For such a case, prepend the
                 // scheme and host, because the 'Location' header must be absolute.
                 if (strpos($destination, '/') === 0) {
                     $destination = $request->getSchemeAndHttpHost() . $destination;
                 } else {
                     // Legacy destination query parameters can be relative paths that
                     // have not yet been converted to URLs (outbound path processors
                     // and other URL handling still needs to be performed).
                     // @todo As generateFromPath() is deprecated, remove this in
                     //   https://www.drupal.org/node/2418219.
                     $destination = UrlHelper::parse($destination);
                     $path = $destination['path'];
                     $options['query'] = $destination['query'];
                     $options['fragment'] = $destination['fragment'];
                     // The 'Location' HTTP header must always be absolute.
                     $options['absolute'] = TRUE;
                     $destination = $this->urlGenerator->generateFromPath($path, $options);
                 }
                 $response->setTargetUrl($destination);
             } elseif (UrlHelper::externalIsLocal($destination, $this->requestContext->getCompleteBaseUrl())) {
                 $response->setTargetUrl($destination);
             }
         }
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:48,代码来源:RedirectResponseSubscriber.php

示例8: checkRedirectUrl

 /**
  * Allows manipulation of the response object when performing a redirect.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The Event to process.
  */
 public function checkRedirectUrl(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($response instanceof RedirectResponse) {
         $options = array();
         $destination = $event->getRequest()->query->get('destination');
         // A destination from \Drupal::request()->query always overrides the
         // current RedirectResponse. We do not allow absolute URLs to be passed
         // via \Drupal::request()->query, as this can be an attack vector, with
         // the following exception:
         // - Absolute URLs that point to this site (i.e. same base URL and
         //   base path) are allowed.
         if ($destination && (!UrlHelper::isExternal($destination) || UrlHelper::externalIsLocal($destination, $GLOBALS['base_url']))) {
             $destination = UrlHelper::parse($destination);
             $path = $destination['path'];
             $options['query'] = $destination['query'];
             $options['fragment'] = $destination['fragment'];
             // The 'Location' HTTP header must always be absolute.
             $options['absolute'] = TRUE;
             $response->setTargetUrl($this->urlGenerator->generateFromPath($path, $options));
         }
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:RedirectResponseSubscriber.php

示例9: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $langcode = $this->entity->id();
     // Warn and redirect user when attempting to delete the default language.
     if (language_default()->id == $langcode) {
         drupal_set_message($this->t('The default language cannot be deleted.'));
         $url = $this->urlGenerator->generateFromPath('admin/config/regional/language', array('absolute' => TRUE));
         return new RedirectResponse($url);
     }
     // Throw a 404 when attempting to delete a non-existing language.
     $languages = language_list();
     if (!isset($languages[$langcode])) {
         throw new NotFoundHttpException();
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:19,代码来源:LanguageDeleteForm.php

示例10: redirectForm

 /**
  * {@inheritdoc}
  */
 public function redirectForm(FormStateInterface $form_state)
 {
     // According to RFC 7231, 303 See Other status code must be used to redirect
     // user agent (and not default 302 Found).
     // @see http://tools.ietf.org/html/rfc7231#section-6.4.4
     $status_code = Response::HTTP_SEE_OTHER;
     $redirect = $form_state->getRedirect();
     // Allow using redirect responses directly if needed.
     if ($redirect instanceof RedirectResponse) {
         return $redirect;
     }
     $url = NULL;
     // Check for a route-based redirection.
     if ($redirect instanceof Url) {
         $url = $redirect->toString();
     } elseif (is_array($redirect)) {
         if (isset($redirect[1])) {
             $options = $redirect[1];
         } else {
             $options = array();
         }
         // Redirections should always use absolute URLs.
         $options['absolute'] = TRUE;
         if (isset($redirect[2])) {
             $status_code = $redirect[2];
         }
         $url = $this->urlGenerator->generateFromPath($redirect[0], $options);
     } elseif (is_string($redirect)) {
         // This function can be called from the installer, which guarantees
         // that $redirect will always be a string, so catch that case here
         // and use the appropriate redirect function.
         if ($this->drupalInstallationAttempted()) {
             install_goto($redirect);
         } else {
             $url = $this->urlGenerator->generateFromPath($redirect, array('absolute' => TRUE));
         }
     } elseif ($redirect === NULL) {
         $request = $this->requestStack->getCurrentRequest();
         // @todo Remove dependency on the internal _system_path attribute:
         //   https://www.drupal.org/node/2293521.
         $url = $this->urlGenerator->generateFromPath($request->attributes->get('_system_path'), array('query' => $request->query->all(), 'absolute' => TRUE));
     }
     if ($url) {
         return new RedirectResponse($url, $status_code);
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:49,代码来源:FormSubmitter.php

示例11: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = NULL)
 {
     $form_state['step'] = isset($form_state['step']) ? $form_state['step'] : 'views_form_views_form';
     $form_state['step_controller']['views_form_views_form'] = 'Drupal\\views\\Form\\ViewsFormMainForm';
     // Cache the built form to prevent it from being rebuilt prior to validation
     // and submission, which could lead to data being processed incorrectly,
     // because the views rows (and thus, the form elements as well) have changed
     // in the meantime.
     $form_state['cache'] = TRUE;
     $form = array();
     $query = $this->requestStack->getCurrentRequest()->query->all();
     $query = UrlHelper::filterQueryParameters($query, array(), '');
     $form['#action'] = $this->urlGenerator->generateFromPath($view->getUrl(), array('query' => $query));
     // Tell the preprocessor whether it should hide the header, footer, pager...
     $form['show_view_elements'] = array('#type' => 'value', '#value' => $form_state['step'] == 'views_form_views_form' ? TRUE : FALSE);
     $form_object = $this->getFormObject($form_state);
     $form += $form_object->buildForm($form, $form_state, $view, $output);
     return $form;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:22,代码来源:ViewsForm.php

示例12: getDestinationAsAbsoluteUrl

 /**
  * Converts the passed in destination into an absolute URL.
  *
  * @param string $destination
  *   The path for the destination. In case it starts with a slash it should
  *   have the base path included already.
  * @param string $scheme_and_host
  *   The scheme and host string of the current request.
  *
  * @return string
  *   The destination as absolute URL.
  */
 protected function getDestinationAsAbsoluteUrl($destination, $scheme_and_host)
 {
     if (!UrlHelper::isExternal($destination)) {
         // The destination query parameter can be a relative URL in the sense of
         // not including the scheme and host, but its path is expected to be
         // absolute (start with a '/'). For such a case, prepend the scheme and
         // host, because the 'Location' header must be absolute.
         if (strpos($destination, '/') === 0) {
             $destination = $scheme_and_host . $destination;
         } else {
             // Legacy destination query parameters can be relative paths that have
             // not yet been converted to URLs (outbound path processors and other
             // URL handling still needs to be performed).
             // @todo As generateFromPath() is deprecated, remove this in
             //   https://www.drupal.org/node/2418219.
             $destination = UrlHelper::parse($destination);
             $path = $destination['path'];
             $options = ['query' => $destination['query'], 'fragment' => $destination['fragment'], 'absolute' => TRUE];
             $destination = $this->urlGenerator->generateFromPath($path, $options);
         }
     }
     return $destination;
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:35,代码来源:RedirectResponseSubscriber.php

示例13: redirectForm

 /**
  * {@inheritdoc}
  */
 public function redirectForm(FormStateInterface $form_state)
 {
     $redirect = $form_state->getRedirect();
     // Allow using redirect responses directly if needed.
     if ($redirect instanceof RedirectResponse) {
         return $redirect;
     }
     $url = NULL;
     // Check for a route-based redirection.
     if ($redirect instanceof Url) {
         $url = $redirect->setAbsolute()->toString();
     } elseif ($redirect === NULL) {
         $request = $this->requestStack->getCurrentRequest();
         // @todo Remove dependency on the internal _system_path attribute:
         //   https://www.drupal.org/node/2293521.
         $url = $this->urlGenerator->generateFromPath($request->attributes->get('_system_path'), array('query' => $request->query->all(), 'absolute' => TRUE));
     }
     if ($url) {
         // According to RFC 7231, 303 See Other status code must be used to redirect
         // user agent (and not default 302 Found).
         // @see http://tools.ietf.org/html/rfc7231#section-6.4.4
         return new RedirectResponse($url, Response::HTTP_SEE_OTHER);
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:27,代码来源:FormSubmitter.php

示例14: render

 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $build = parent::render();
     $build['#empty'] = t('No content types available. <a href="@link">Add content type</a>.', array('@link' => $this->urlGenerator->generateFromPath('admin/structure/types/add')));
     return $build;
 }
开发者ID:brstde,项目名称:gap1,代码行数:9,代码来源:NodeTypeListBuilder.php

示例15: getUrlFromPath

 /**
  * Generates an absolute URL given a path.
  *
  * @param string $path
  *   The path.
  * @param array $options
  *   (optional) An associative array of additional options. The 'absolute'
  *   option is forced to be TRUE.
  *
  * @return string
  *   The generated absolute URL for the given path.
  */
 public function getUrlFromPath($path, $options = array())
 {
     $options['absolute'] = TRUE;
     return $this->urlGenerator->generateFromPath($path, $options);
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:17,代码来源:TwigExtension.php


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