本文整理汇总了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]));
}
示例2: testAccessManager
/**
* Tests the accessManager() method.
*
* @covers ::accessManager
*/
public function testAccessManager()
{
$this->setMockContainerService('access_manager');
$this->assertNotNull(\Drupal::accessManager());
}