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


PHP Drupal::accessManager方法代码示例

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


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

示例1: iClickTheContextualLinkInTheRegion

 /**
  * Resolves contextual links directly, without the need for javascript.
  *
  * @Then I click the contextual link :linkText in the :region region
  */
 public function iClickTheContextualLinkInTheRegion($linkText, $region)
 {
     $account = user_load($this->getUserManager()->getCurrentUser()->uid);
     $links = array();
     /** @var \Drupal\Core\Menu\ContextualLinkManager $contextual_links_manager */
     $contextual_links_manager = \Drupal::service('plugin.manager.menu.contextual_link');
     $session = $this->getSession();
     $regionObj = $session->getPage()->find('region', $region);
     if (!$regionObj) {
         throw new \Exception(sprintf('No region "%s" found on the page %s.', $region, $session->getCurrentUrl()));
     }
     /** @var \Behat\Mink\Element\NodeElement $item */
     foreach ($regionObj->findAll('xpath', '//*[@data-contextual-id]') as $item) {
         $contextual_id = $item->getAttribute('data-contextual-id');
         foreach (_contextual_id_to_links($contextual_id) as $group_name => $link) {
             $route_parameters = $link['route_parameters'];
             foreach ($contextual_links_manager->getContextualLinkPluginsByGroup($group_name) as $plugin_id => $plugin_definition) {
                 /** @var \Drupal\Core\Menu\ContextualLinkInterface $plugin */
                 $plugin = $contextual_links_manager->createInstance($plugin_id);
                 $route_name = $plugin->getRouteName();
                 // Check access.
                 if (!\Drupal::accessManager()->checkNamedRoute($route_name, $route_parameters, $account)) {
                     continue;
                 }
                 /** @var \Drupal\Core\Url $url */
                 $url = Url::fromRoute($route_name, $route_parameters, $plugin->getOptions())->toRenderArray();
                 $links[$plugin->getTitle()] = $url['#url']->toString();
             }
         }
     }
     if (isset($links[$linkText])) {
         $session->visit($this->locatePath($links[$linkText]));
         return;
     }
     throw new \Exception(t('Could not find a contextual link %link in the region %region', ['%link' => $linkText, '%region' => $region]));
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:41,代码来源:DrupalContext.php

示例2: testAccessManager

 /**
  * Tests the accessManager() method.
  *
  * @covers ::accessManager
  */
 public function testAccessManager()
 {
     $this->setMockContainerService('access_manager');
     $this->assertNotNull(\Drupal::accessManager());
 }
开发者ID:dmyerson,项目名称:d8ecs,代码行数:10,代码来源:DrupalTest.php


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