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


PHP Drupal::routeMatch方法代码示例

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


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

示例1: preprocessVariables

 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables)
 {
     $breadcrumb =& $variables['breadcrumb'];
     // Determine if breadcrumbs should be displayed.
     $breadcrumb_visibility = $this->theme->getSetting('breadcrumb');
     if ($breadcrumb_visibility == 0 || $breadcrumb_visibility == 2 && \Drupal::service('router.admin_context')->isAdminRoute() || empty($breadcrumb)) {
         $breadcrumb = [];
         return;
     }
     // Optionally get rid of the homepage link.
     $show_breadcrumb_home = $this->theme->getSetting('breadcrumb_home');
     if (!$show_breadcrumb_home) {
         array_shift($breadcrumb);
     }
     if ($this->theme->getSetting('breadcrumb_title') && !empty($breadcrumb)) {
         $request = \Drupal::request();
         $route_match = \Drupal::routeMatch();
         $page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
         if (!empty($page_title)) {
             $breadcrumb[] = ['text' => $page_title, 'attributes' => new Attribute(['class' => ['active']])];
             // Add cache context based on url.
             $variables->addCacheContexts(['url']);
         }
     }
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:28,代码来源:Breadcrumb.php

示例2: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $block = array('#theme' => 'fblikebutton', '#layout' => $this->configuration['layout'], '#show_faces' => $this->configuration['show_faces'], '#action' => $this->configuration['action'], '#font' => $this->configuration['font'], '#color_scheme' => $this->configuration['color_scheme'], '#width' => $this->configuration['iframe_width'], '#height' => $this->configuration['iframe_height'], '#other_css' => $this->configuration['iframe_css'], '#language' => $this->configuration['language']);
     // If it's not for the current page
     if ($this->configuration['block_url'] != '<current>') {
         $block['#url'] = $this->configuration['block_url'];
     } else {
         // Avoid this block to be cached
         $block['#cache'] = array('max-age' => 0);
         /**
          * Drupal uses the /node path to refers to the frontpage. That's why facebook
          * could point to www.example.com/node instead of wwww.example.com.
          * 
          * To avoid this, we check if the current path is the frontpage
          */
         // Check if the path is pointing home
         if (\Drupal::routeMatch()->getRouteName() == 'view.frontpage.page_1') {
             global $base_url;
             $block['#url'] = $base_url;
         } else {
             $block['#url'] = Url::fromRoute('<current>', array(), array('absolute' => true))->toString();
         }
     }
     return $block;
 }
开发者ID:badelas,项目名称:afroweb,代码行数:28,代码来源:FblikebuttonBlock.php

示例3: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $items = array();
     // When on a node page, the parameter is already upcast as a node.
     $node = \Drupal::routeMatch()->getParameter('node');
     if ($node) {
         // Read about entity query at http://www.sitepoint.com/drupal-8-version-entityfieldquery/.
         // See query API at https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Query%21QueryInterface.php/interface/QueryInterface/8.
         // The static method for using the query service would have been:
         // $query = \Drupal::entityQuery('node');
         // Use injected queryFactory to look for items that are related
         // to the show that matches the input nid.
         $query = $this->entity_query->get('node')->condition('status', 1)->condition('type', 'tv_episode')->sort('field_related_season.entity.field_season_number.value', 'DESC')->sort('field_episode_number', 'DESC')->range(0, 5)->condition('field_related_season.entity.field_related_show.entity.nid', $node->id());
         $nids = $query->execute();
         // Note that entity_load() is deprecated.
         // The static method of loading the entity would have been:
         // \Drupal\node\Entity\Node::load();
         // Use the injected entityManager to load the results into an array of node objects.
         $nodes = $this->entity_manager->getStorage('node')->loadMultiple($nids);
         foreach ($nodes as $node) {
             // Create a render array for each title field.
             // Note that field_view_field() is deprecated, use the view method on the field.
             $title = $node->title->view('full');
             // Entities have a handy toLink() method.
             $items[] = $node->toLink($title);
         }
     }
     // Return a render array for a html list.
     return ['#theme' => 'item_list', '#items' => $items, '#cache' => ['contexts' => ['route']]];
 }
开发者ID:Lullabot,项目名称:challenge4,代码行数:33,代码来源:DemoBlock.php

示例4: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $request = \Drupal::request();
     $route_match = \Drupal::routeMatch();
     $title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
     return array('#markup' => $title);
 }
开发者ID:protitude,项目名称:zap,代码行数:10,代码来源:HelloBlock.php

示例5: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $OriginalValue = '';
     if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof \Drupal\node\NodeInterface) {
         $FiledsView = $items->view();
         $LangCode = $items->getLangcode();
         $FieldName = $FiledsView['#field_name'];
         $node = (array) $node;
         $arrayValues = array_values($node);
         if (isset($arrayValues[0]['langcode']['x-default']) && $arrayValues[0]['langcode']['x-default'] != $LangCode) {
             if ($FieldName != 'title') {
                 if (isset($arrayValues[0][$FieldName]['x-default'][0]['value'])) {
                     $OriginalValue = $arrayValues[0][$FieldName]['x-default'][0]['value'];
                 }
             } else {
                 if (isset($arrayValues[0][$FieldName]['x-default'])) {
                     $OriginalValue = $arrayValues[0][$FieldName]['x-default'];
                 }
             }
             $Title = $OriginalValue;
             $OriginalValue = Unicode::truncate($OriginalValue, 200, TRUE);
             $OriginalValue = '<div class="original_text" title="' . $Title . '"><span class="original">ORIGINAL: </span>' . $OriginalValue . '</div>';
         }
     }
     $element['value'] = $element + array('#type' => 'textfield', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'), '#maxlength' => $this->getFieldSetting('max_length'), '#attributes' => array('class' => array('text-full')), '#suffix' => $OriginalValue);
     return $element;
 }
开发者ID:brstde,项目名称:gap1,代码行数:30,代码来源:StringTextfieldWidget.php

示例6: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     //TODO v2 Send Email via Cron not on Submit
     $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
     $username = $user->get('name')->value;
     $userId = $user->get('uid')->value;
     $mailManager = \Drupal::service('plugin.manager.mail');
     $jobNode = \Drupal::routeMatch()->getParameter('node');
     $jobNodeTitle = $jobNode->getTitle();
     $companyNodeEntity = $jobNode->get('field_company');
     $companyNode = \Drupal\node\Entity\Node::load($companyNodeEntity->entity->id());
     $companyEmail = $companyNode->field_email->value;
     $resumeFileId = $form_state->getValue('resume');
     $resumeFile = db_select('file_managed', 'f')->condition('f.fid', $resumeFileId, '=')->fields('f', array('uri'))->execute()->fetchField();
     $atttachment = array('filepath' => $resumeFile);
     $module = 'job_mailer';
     $key = 'apply_job';
     $params['job_title'] = $jobNodeTitle;
     $params['message'] = "<html>\n           <p>Please see attached resume for user: {$username}\n           </html>";
     $params['attachment'] = $atttachment;
     $langcode = \Drupal::currentUser()->getPreferredLangcode();
     $send = true;
     $reply = \Drupal::config('system.site')->get('mail');
     $result = $mailManager->mail($module, $key, $companyEmail, $langcode, $params, $reply, $send);
     db_insert('user_job_application')->fields(array('job_id' => $jobNode->id(), 'user_id' => $userId, 'date' => date('Y-m-d H:i:s')))->execute();
     drupal_set_message('Your application has been sent.');
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:30,代码来源:ApplyForm.php

示例7: onRequest

 /**
  * @event kernel.controller
  * @priority 9999
  * @param FilterControllerEvent $e
  */
 static function onRequest($e)
 {
     if ($variants = Submodules::fastInvoke('route_alter_variants')[\Drupal::routeMatch()->getRouteName()] ?? NULL) {
         foreach ($variants as $variant) {
             if (!isset($variant['applies']) || is_callable($variant['applies']) && $variant['applies']()) {
                 $e->setController($variant['controller']);
                 break;
             }
         }
     }
 }
开发者ID:d-f-d,项目名称:d_submodules,代码行数:16,代码来源:RouteAlterLoader.php

示例8: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     // Get the current node.
     $node = \Drupal::routeMatch()->getParameter('node');
     // Build the field quiz answer form
     $form_object = new FieldQuizAnswerForm($node, $items);
     $form = \Drupal::formBuilder()->getForm($form_object);
     $elements = array();
     // Add the output to the node.
     $elements[] = $build['field_quiz'] = ['#theme' => 'field_quiz_question_view', '#form' => $form];
     return $elements;
 }
开发者ID:badelas,项目名称:afroweb,代码行数:15,代码来源:QuestionTextFormatter.php

示例9: revertAccess

 /**
  * Access check, to be called from
  * - module.routing.yml
  * - hook_entity_operation
  *
  * @param \Drupal\workflow_operations\WorkflowTransitionInterface|NULL $transition
  *
  * @return \Drupal\Core\Access\AccessResult
  */
 public function revertAccess(WorkflowTransitionInterface $transition = NULL, AccountInterface $account = NULL, $return_as_object = TRUE)
 {
     //public function access(EntityInterface $entity, $operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
     if ($transition) {
         // Called from hook_entity_operation
     } else {
         // Called from module.routing.yml
         /* @var $transition WorkflowTransitionInterface */
         $route_match = \Drupal::routeMatch();
         $transition = $route_match->getParameter('workflow_transition');
     }
     return $this->access($transition, 'revert', $account, $return_as_object);
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:22,代码来源:WorkflowAccessControlHandler.php

示例10: testConfigTranslationFormAlter

 /**
  * Tests altering of the configuration translation forms.
  */
 public function testConfigTranslationFormAlter()
 {
     $form_builder = \Drupal::formBuilder();
     $add_form = $form_builder->getForm('Drupal\\config_translation\\Form\\ConfigTranslationAddForm', \Drupal::routeMatch(), $this->pluginId, $this->langcode);
     $edit_form = $form_builder->getForm('Drupal\\config_translation\\Form\\ConfigTranslationEditForm', \Drupal::routeMatch(), $this->pluginId, $this->langcode);
     // Test that hook_form_BASE_FORM_ID_alter() was called for the base form ID
     // 'config_translation_form'.
     $this->assertTrue($add_form['#base_altered']);
     $this->assertTrue($edit_form['#base_altered']);
     // Test that hook_form_FORM_ID_alter() was called for the form IDs
     // 'config_translation_add_form' and 'config_translation_edit_form'.
     $this->assertTrue($add_form['#altered']);
     $this->assertTrue($edit_form['#altered']);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:ConfigTranslationFormTest.php

示例11: addAnotherAccess

 /**
  * Takes the user to the node creation page for the type of a given node.
  */
 public function addAnotherAccess(NodeInterface $node)
 {
     if (!$node->access('create')) {
         return AccessResult::forbidden();
     }
     $config = \Drupal::config('addanother.settings');
     $account = \Drupal::currentUser();
     $type = $node->getType();
     if (\Drupal::routeMatch()->getRouteName() == 'entity.node.edit_form' && !$config->get('tab_edit.' . $type)) {
         return AccessResult::forbidden();
     }
     if ($config->get('tab.' . $type) && $account->hasPermission('use add another')) {
         return AccessResult::allowed();
     }
     return AccessResult::forbidden();
 }
开发者ID:mkdok,项目名称:d8-addanother,代码行数:19,代码来源:AddAnotherController.php

示例12: onAccessDeniedException

 /**
  * Set the properly exception for event.
  */
 public function onAccessDeniedException(GetResponseForExceptionEvent $event)
 {
     if ($event->getException() instanceof AccessDeniedHttpException) {
         $admin_only = \Drupal::config('m4032404.settings')->get('admin_only');
         $route = \Drupal::routeMatch()->getRouteObject();
         $is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);
         if ($admin_only && !$is_admin) {
             // @todo revisit this when r4032login is ready for 8.x.
             if (function_exists('r4032login_redirect')) {
                 return r4032login_redirect();
             }
         } else {
             $event->setException(new NotFoundHttpException());
         }
     }
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:19,代码来源:m4032404EventSubscriber.php

示例13: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $id = $this->configuration['message'];
     // Figure out what page is being viewed.
     $path = \Drupal::routeMatch()->getRouteName();
     $messages = $this->options();
     if ($id == 0) {
         // Calculate which message to show based on a hash of the path and the
         // site's private key. The message initially chosen for each page on a
         // specific site will thus be pseudo-random, yet we will consistently
         // display the same message on any given page on that site.
         $private_key = \Drupal::service('private_key')->get();
         $id = hexdec(substr(md5($path . $private_key), 0, 2)) % count($messages) + 1;
     }
     return array('#markup' => $messages[$id]);
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:19,代码来源:PoweredByBlock.php

示例14: applies

 /**
  * {@inheritdoc}
  */
 public function applies(RouteMatchInterface $route_match)
 {
     $this->oUser = \Drupal::currentUser();
     $aUserRoles = $this->oUser->getRoles();
     $bEditorRoleActive = FALSE;
     foreach ($aUserRoles as $sUserRole) {
         if ($sUserRole == 'editor') {
             $bEditorRoleActive = true;
         }
     }
     $route = \Drupal::routeMatch()->getRouteObject();
     $bIsAdminPath = \Drupal::service('router.admin_context')->isAdminRoute($route);
     if ($bEditorRoleActive === TRUE && $bIsAdminPath === TRUE) {
         return true;
     }
 }
开发者ID:jepster,项目名称:GaiaD8,代码行数:19,代码来源:EditorialWorkbenchBreadcrumbBuilder.php

示例15: submitForm

 /**
  * Overrides \Drupal\Core\Entity\EntityFormController::submit().
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Build the block object from the submitted values.
     parent::submitForm($form, $form_state);
     $field_collection_item = $this->entity;
     // TODO: Create new revision every edit?  Might be better to make it an
     // option.  In either case, it doesn't work as is.  The default
     // revision of the host isn't getting updated to point to the new
     // field collection item revision.
     // $field_collection_item->setNewRevision();
     if (\Drupal::routeMatch()->getRouteName() == 'field_collection_item.add_page') {
         $host = entity_load(\Drupal::routeMatch()->getParameter('host_type'), \Drupal::routeMatch()->getParameter('host_id'));
     } else {
         $host = $field_collection_item->getHost();
     }
     $form_state->setRedirect($host->urlInfo()->getRouteName(), $host->urlInfo()->getRouteParameters());
 }
开发者ID:vanilla-bear,项目名称:drupal8,代码行数:20,代码来源:FieldCollectionItemForm.php


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