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


PHP Url::fromRouteMatch方法代码示例

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


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

示例1: isFrontPage

 /**
  * {@inheritdoc}
  */
 public function isFrontPage()
 {
     // Cache the result as this is called often.
     if (!isset($this->isCurrentFrontPage)) {
         $this->isCurrentFrontPage = FALSE;
         // Ensure that the code can also be executed when there is no active
         // route match, like on exception responses.
         if ($this->routeMatch->getRouteName()) {
             $url = Url::fromRouteMatch($this->routeMatch);
             $this->isCurrentFrontPage = $url->getRouteName() && '/' . $url->getInternalPath() === $this->getFrontPagePath();
         }
     }
     return $this->isCurrentFrontPage;
 }
开发者ID:318io,项目名称:318-io,代码行数:17,代码来源:PathMatcher.php

示例2: blockContents

 /**
  * {@inheritdoc}
  */
 public function blockContents()
 {
     $sharethis_config = $this->configFactory->get('sharethis.settings');
     $config = $this->configFactory->get('system.site');
     if ($sharethis_config->get('location') == 'block') {
         // First Get all of the options for sharethis widget from database.
         $data_options = $this->getOptions();
         $current_path = \Drupal::routeMatch()->getRouteName() ? Url::fromRouteMatch(\Drupal::routeMatch())->getInternalPath() : '';
         $path = isset($current_path) ? $current_path : '<front>';
         global $base_url;
         $path_obj = Url::fromUri($base_url . '/' . $path, array('absolute' => TRUE));
         $m_path = $path_obj->toString();
         $request = \Drupal::request();
         $route_match = \Drupal::routeMatch();
         $mtitle = $this->titleResolver->getTitle($request, $route_match->getRouteObject());
         $m_title = is_object($mtitle) ? $mtitle->getUntranslatedString() : $config->get('name');
         return $this->renderSpans($data_options, $m_title, $m_path);
     }
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:22,代码来源:SharethisManager.php

示例3: getStandardButtons

 /**
  * Provide a standard set of Apply/Cancel/OK buttons for the forms. Also provide
  * a hidden op operator because the forms plugin doesn't seem to properly
  * provide which button was clicked.
  *
  * TODO: Is the hidden op operator still here somewhere, or is that part of the
  * docblock outdated?
  */
 public function getStandardButtons(&$form, FormStateInterface $form_state, $form_id, $name = NULL)
 {
     $form['actions'] = array('#type' => 'actions');
     if (empty($name)) {
         $name = t('Apply');
         if (!empty($this->stack) && count($this->stack) > 1) {
             $name = t('Apply and continue');
         }
         $names = array(t('Apply'), t('Apply and continue'));
     }
     // Views provides its own custom handling of AJAX form submissions. Usually
     // this happens at the same path, but custom paths may be specified in
     // $form_state.
     $form_url = $form_state->get('url') ?: Url::fromRouteMatch(\Drupal::routeMatch());
     // Forms that are purely informational set an ok_button flag, so we know not
     // to create an "Apply" button for them.
     if (!$form_state->get('ok_button')) {
         $form['actions']['submit'] = array('#type' => 'submit', '#value' => $name, '#id' => 'edit-submit-' . Html::getUniqueId($form_id), '#submit' => array(array($this, 'standardSubmit')), '#button_type' => 'primary', '#ajax' => array('url' => $form_url));
         // Form API button click detection requires the button's #value to be the
         // same between the form build of the initial page request, and the
         // initial form build of the request processing the form submission.
         // Ideally, the button's #value shouldn't change until the form rebuild
         // step. However, \Drupal\views_ui\Form\Ajax\ViewsFormBase::getForm()
         // implements a different multistep form workflow than the Form API does,
         // and adjusts $view->stack prior to form processing, so we compensate by
         // extending button click detection code to support any of the possible
         // button labels.
         if (isset($names)) {
             $form['actions']['submit']['#values'] = $names;
             $form['actions']['submit']['#process'] = array_merge(array('views_ui_form_button_was_clicked'), \Drupal::service('element_info')->getInfoProperty($form['actions']['submit']['#type'], '#process', array()));
         }
         // If a validation handler exists for the form, assign it to this button.
         $form['actions']['submit']['#validate'][] = [$form_state->getFormObject(), 'validateForm'];
     }
     // Create a "Cancel" button. For purely informational forms, label it "OK".
     $cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : array($this, 'standardCancel');
     $form['actions']['cancel'] = array('#type' => 'submit', '#value' => !$form_state->get('ok_button') ? t('Cancel') : t('Ok'), '#submit' => array($cancel_submit), '#validate' => array(), '#ajax' => array('path' => $form_url), '#limit_validation_errors' => array());
     // Compatibility, to be removed later: // TODO: When is "later"?
     // We used to set these items on the form, but now we want them on the $form_state:
     if (isset($form['#title'])) {
         $form_state->set('title', $form['#title']);
     }
     if (isset($form['#section'])) {
         $form_state->set('#section', $form['#section']);
     }
     // Finally, we never want these cached -- our object cache does that for us.
     $form['#no_cache'] = TRUE;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:56,代码来源:ViewUI.php

示例4: testFromRouteMatch

 /**
  * Tests the fromRouteMatch() method.
  */
 public function testFromRouteMatch()
 {
     $route = new Route('/test-route/{foo}');
     $route_match = new RouteMatch('test_route', $route, ['foo' => (object) [1]], ['foo' => 1]);
     $url = Url::fromRouteMatch($route_match);
     $this->assertSame('test_route', $url->getRouteName());
     $this->assertEquals(['foo' => '1'], $url->getRouteParameters());
 }
开发者ID:318io,项目名称:318-io,代码行数:11,代码来源:UrlTest.php

示例5: buildForm

 /**
  * {@inheritdoc}
  */
 function buildForm(array $form, FormStateInterface $form_state, array $build = NULL)
 {
     // Store the entity in the form state so we can easily create the job in the
     // submit handler.
     $form_state->set('entity', $build['#entity']);
     $overview = $build['content_translation_overview'];
     $form['#title'] = $this->t('Translations of @title', array('@title' => $build['#entity']->label()));
     $form['actions'] = array('#type' => 'details', '#title' => t('Operations'), '#open' => TRUE, '#attributes' => array('class' => array('tmgmt-source-operations-wrapper')));
     $form['actions']['request'] = array('#type' => 'submit', '#button_type' => 'primary', '#value' => $this->t('Request translation'), '#submit' => array('::submitForm'));
     tmgmt_add_cart_form($form['actions'], $form_state, 'content', $form_state->get('entity')->getEntityTypeId(), $form_state->get('entity')->id());
     // Inject our additional column into the header.
     array_splice($overview['#header'], -1, 0, array(t('Pending Translations')));
     // Make this a tableselect form.
     $form['languages'] = array('#type' => 'tableselect', '#header' => $overview['#header'], '#options' => array());
     $languages = \Drupal::languageManager()->getLanguages();
     // Check if there is a job / job item that references this translation.
     $entity_langcode = $form_state->get('entity')->language()->getId();
     $items = tmgmt_job_item_load_latest('content', $form_state->get('entity')->getEntityTypeId(), $form_state->get('entity')->id(), $entity_langcode);
     foreach ($languages as $langcode => $language) {
         if ($langcode == LanguageInterface::LANGCODE_DEFAULT) {
             // Never show language neutral on the overview.
             continue;
         }
         // Since the keys are numeric and in the same order we can shift one element
         // after the other from the original non-form rows.
         $option = array_shift($overview['#rows']);
         if ($langcode == $entity_langcode) {
             $additional = array('data' => array('#markup' => '<strong>' . t('Source') . '</strong>'));
             // This is the source object so we disable the checkbox for this row.
             $form['languages'][$langcode] = array('#type' => 'checkbox', '#disabled' => TRUE);
         } elseif (isset($items[$langcode])) {
             $item = $items[$langcode];
             $states = JobItem::getStates();
             $path = \Drupal::routeMatch()->getRouteName() ? Url::fromRouteMatch(\Drupal::routeMatch())->getInternalPath() : '';
             $destination = array('destination' => $path);
             $additional = \Drupal::l($states[$item->getState()], $item->urlInfo()->setOption('query', $destination));
             // Disable the checkbox for this row since there is already a translation
             // in progress that has not yet been finished. This way we make sure that
             // we don't stack multiple active translations for the same item on top
             // of each other.
             $form['languages'][$langcode] = array('#type' => 'checkbox', '#disabled' => TRUE);
         } else {
             // There is no translation job / job item for this target language.
             $additional = t('None');
         }
         // Inject the additional column into the array.
         // The generated form structure has changed, support both an additional
         // 'data' key (that is not supported by tableselect) and the old version
         // without.
         if (isset($option['data'])) {
             array_splice($option['data'], -1, 0, array($additional));
             // Append the current option array to the form.
             $form['languages']['#options'][$langcode] = $option['data'];
         } else {
             array_splice($option, -1, 0, array($additional));
             // Append the current option array to the form.
             $form['languages']['#options'][$langcode] = $option;
         }
     }
     return $form;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:64,代码来源:ContentTranslateForm.php

示例6: build

 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $links = array();
     // General path-based breadcrumbs. Use the actual request path, prior to
     // resolving path aliases, so the breadcrumb can be defined by simply
     // creating a hierarchy of path aliases.
     $path = trim($this->context->getPathInfo(), '/');
     $path_elements = explode('/', $path);
     $exclude = array();
     // Don't show a link to the front-page path.
     $front = $this->config->get('page.front');
     $exclude[$front] = TRUE;
     // /user is just a redirect, so skip it.
     // @todo Find a better way to deal with /user.
     $exclude['user'] = TRUE;
     while (count($path_elements) > 1) {
         array_pop($path_elements);
         // Copy the path elements for up-casting.
         $route_request = $this->getRequestForPath(implode('/', $path_elements), $exclude);
         if ($route_request) {
             $route_match = RouteMatch::createFromRequest($route_request);
             $access = $this->accessManager->check($route_match, $this->currentUser);
             if ($access) {
                 $title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject());
             }
             if ($access) {
                 if (!isset($title)) {
                     // Fallback to using the raw path component as the title if the
                     // route is missing a _title or _title_callback attribute.
                     $title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
                 }
                 $url = Url::fromRouteMatch($route_match);
                 $links[] = new Link($title, $url);
             }
         }
     }
     if ($path && $path != $front) {
         // Add the Home link, except for the front page.
         $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     }
     return array_reverse($links);
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:45,代码来源:PathBasedBreadcrumbBuilder.php


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