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


PHP AccessManagerInterface::checkNamedRoute方法代码示例

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


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

示例1: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     switch ($operation) {
         case 'view':
             // There is no direct viewing of a menu link, but still for purposes of
             // content_translation we need a generic way to check access.
             return AccessResult::allowedIfHasPermission($account, 'administer menu');
         case 'update':
             if (!$account->hasPermission('administer menu')) {
                 return AccessResult::neutral()->cachePerPermissions();
             } else {
                 // If there is a URL, this is an external link so always accessible.
                 $access = AccessResult::allowed()->cachePerPermissions()->addCacheableDependency($entity);
                 /** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */
                 // We allow access, but only if the link is accessible as well.
                 if (($url_object = $entity->getUrlObject()) && $url_object->isRouted()) {
                     $link_access = $this->accessManager->checkNamedRoute($url_object->getRouteName(), $url_object->getRouteParameters(), $account, TRUE);
                     $access = $access->andIf($link_access);
                 }
                 return $access;
             }
         case 'delete':
             return AccessResult::allowedIf(!$entity->isNew() && $account->hasPermission('administer menu'))->cachePerPermissions()->addCacheableDependency($entity);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:MenuLinkContentAccessControlHandler.php

示例2: render

 /**
  * {@inheritdoc}
  */
 public function render($empty = FALSE)
 {
     $account = \Drupal::currentUser();
     if (!$empty || !empty($this->options['empty'])) {
         $element = array('#theme' => 'links', '#links' => array(array('url' => Url::fromRoute('node.add_page'), 'title' => $this->t('Add content'))), '#access' => $this->accessManager->checkNamedRoute('node.add_page', array(), $account));
         return $element;
     }
     return array();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:12,代码来源:ListingEmpty.php

示例3: render

 /**
  * {@inheritdoc}
  */
 public function render($empty = FALSE)
 {
     if (!$empty || !empty($this->options['empty'])) {
         /** @var \Drupal\Core\Access\AccessResultInterface|\Drupal\Core\Cache\CacheableDependencyInterface $access_result */
         $access_result = $this->accessManager->checkNamedRoute('block_content.add_page', array(), $this->currentUser, TRUE);
         $element = array('#markup' => $this->t('Add a <a href=":url">custom block</a>.', array(':url' => Url::fromRoute('block_content.add_page')->toString())), '#access' => $access_result->isAllowed(), '#cache' => ['contexts' => $access_result->getCacheContexts(), 'tags' => $access_result->getCacheTags(), 'max-age' => $access_result->getCacheMaxAge()]);
         return $element;
     }
     return array();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:ListingEmpty.php

示例4: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     switch ($operation) {
         case 'view':
             // There is no direct view.
             return FALSE;
         case 'update':
             // If there is a URL, this is an external link so always accessible.
             return $account->hasPermission('administer menu') && ($entity->getUrl() || $this->accessManager->checkNamedRoute($entity->getRouteName(), $entity->getRouteParameters(), $account));
         case 'delete':
             return !$entity->isNew() && $account->hasPermission('administer menu');
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:16,代码来源:MenuLinkContentAccessController.php

示例5: getTasksBuild

 /**
  * {@inheritdoc}
  */
 public function getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheability)
 {
     $tree = $this->getLocalTasksForRoute($current_route_name);
     $build = array();
     // Collect all route names.
     $route_names = array();
     foreach ($tree as $instances) {
         foreach ($instances as $child) {
             $route_names[] = $child->getRouteName();
         }
     }
     // Pre-fetch all routes involved in the tree. This reduces the number
     // of SQL queries that would otherwise be triggered by the access manager.
     $routes = $route_names ? $this->routeProvider->getRoutesByNames($route_names) : array();
     foreach ($tree as $level => $instances) {
         /** @var $instances \Drupal\Core\Menu\LocalTaskInterface[] */
         foreach ($instances as $plugin_id => $child) {
             $route_name = $child->getRouteName();
             $route_parameters = $child->getRouteParameters($this->routeMatch);
             // Given that the active flag depends on the route we have to add the
             // route cache context.
             $cacheability->addCacheContexts(['route']);
             $active = $this->isRouteActive($current_route_name, $route_name, $route_parameters);
             // The plugin may have been set active in getLocalTasksForRoute() if
             // one of its child tabs is the active tab.
             $active = $active || $child->getActive();
             // @todo It might make sense to use link render elements instead.
             $link = ['title' => $this->getTitle($child), 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $child->getOptions($this->routeMatch)];
             $access = $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account, TRUE);
             $build[$level][$plugin_id] = ['#theme' => 'menu_local_task', '#link' => $link, '#active' => $active, '#weight' => $child->getWeight(), '#access' => $access];
             $cacheability->addCacheableDependency($access)->addCacheableDependency($child);
         }
     }
     return $build;
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:38,代码来源:LocalTaskManager.php

示例6: getTasksBuild

 /**
  * {@inheritdoc}
  */
 public function getTasksBuild($current_route_name)
 {
     $tree = $this->getLocalTasksForRoute($current_route_name);
     $build = array();
     // Collect all route names.
     $route_names = array();
     foreach ($tree as $instances) {
         foreach ($instances as $child) {
             $route_names[] = $child->getRouteName();
         }
     }
     // Pre-fetch all routes involved in the tree. This reduces the number
     // of SQL queries that would otherwise be triggered by the access manager.
     $routes = $route_names ? $this->routeProvider->getRoutesByNames($route_names) : array();
     foreach ($tree as $level => $instances) {
         /** @var $instances \Drupal\Core\Menu\LocalTaskInterface[] */
         foreach ($instances as $plugin_id => $child) {
             $route_name = $child->getRouteName();
             $route_parameters = $child->getRouteParameters($this->routeMatch);
             // Find out whether the user has access to the task.
             $access = $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account);
             if ($access) {
                 $active = $this->isRouteActive($current_route_name, $route_name, $route_parameters);
                 // The plugin may have been set active in getLocalTasksForRoute() if
                 // one of its child tabs is the active tab.
                 $active = $active || $child->getActive();
                 // @todo It might make sense to use link render elements instead.
                 $link = array('title' => $this->getTitle($child), 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $child->getOptions($this->routeMatch));
                 $build[$level][$plugin_id] = array('#theme' => 'menu_local_task', '#link' => $link, '#active' => $active, '#weight' => $child->getWeight(), '#access' => $access);
             }
         }
     }
     return $build;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:37,代码来源:LocalTaskManager.php

示例7: itemPage

 /**
  * Language translations overview page for a configuration name.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   Page request object.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match.
  * @param string $plugin_id
  *   The plugin ID of the mapper.
  *
  * @return array
  *   Page render array.
  */
 public function itemPage(Request $request, RouteMatchInterface $route_match, $plugin_id)
 {
     /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
     $mapper = $this->configMapperManager->createInstance($plugin_id);
     $mapper->populateFromRequest($request);
     $page = array();
     $page['#title'] = $this->t('Translations for %label', array('%label' => $mapper->getTitle()));
     $languages = $this->languageManager->getLanguages();
     if (count($languages) == 1) {
         drupal_set_message($this->t('In order to translate configuration, the website must have at least two <a href="@url">languages</a>.', array('@url' => $this->url('entity.configurable_language.collection'))), 'warning');
     }
     $original_langcode = $mapper->getLangcode();
     if (!isset($languages[$original_langcode])) {
         // If the language is not configured on the site, create a dummy language
         // object for this listing only to ensure the user gets useful info.
         $language_name = $this->languageManager->getLanguageName($original_langcode);
         $languages[$original_langcode] = new Language(array('id' => $original_langcode, 'name' => $language_name));
     }
     // We create a fake request object to pass into
     // ConfigMapperInterface::populateFromRequest() for the different languages.
     // Creating a separate request for each language and route is neither easily
     // possible nor performant.
     $fake_request = $request->duplicate();
     $page['languages'] = array('#type' => 'table', '#header' => array($this->t('Language'), $this->t('Operations')));
     foreach ($languages as $language) {
         $langcode = $language->getId();
         // This is needed because
         // ConfigMapperInterface::getAddRouteParameters(), for example,
         // needs to return the correct language code for each table row.
         $fake_request->attributes->set('langcode', $langcode);
         $mapper->populateFromRequest($fake_request);
         // Prepare the language name and the operations depending on whether this
         // is the original language or not.
         if ($langcode == $original_langcode) {
             $language_name = '<strong>' . $this->t('@language (original)', array('@language' => $language->getName())) . '</strong>';
             // Check access for the path/route for editing, so we can decide to
             // include a link to edit or not.
             $edit_access = $this->accessManager->checkNamedRoute($mapper->getBaseRouteName(), $route_match->getRawParameters()->all(), $this->account);
             // Build list of operations.
             $operations = array();
             if ($edit_access) {
                 $operations['edit'] = array('title' => $this->t('Edit'), 'url' => Url::fromRoute($mapper->getBaseRouteName(), $mapper->getBaseRouteParameters(), ['query' => ['destination' => $mapper->getOverviewPath()]]));
             }
         } else {
             $language_name = $language->getName();
             $operations = array();
             // If no translation exists for this language, link to add one.
             if (!$mapper->hasTranslation($language)) {
                 $operations['add'] = array('title' => $this->t('Add'), 'url' => Url::fromRoute($mapper->getAddRouteName(), $mapper->getAddRouteParameters()));
             } else {
                 // Otherwise, link to edit the existing translation.
                 $operations['edit'] = array('title' => $this->t('Edit'), 'url' => Url::fromRoute($mapper->getEditRouteName(), $mapper->getEditRouteParameters()));
                 $operations['delete'] = array('title' => $this->t('Delete'), 'url' => Url::fromRoute($mapper->getDeleteRouteName(), $mapper->getDeleteRouteParameters()));
             }
         }
         $page['languages'][$langcode]['language'] = array('#markup' => $language_name);
         $page['languages'][$langcode]['operations'] = array('#type' => 'operations', '#links' => $operations);
     }
     return $page;
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:73,代码来源:ConfigTranslationController.php

示例8: getActionsForRoute

 /**
  * {@inheritdoc}
  */
 public function getActionsForRoute($route_appears)
 {
     if (!isset($this->instances[$route_appears])) {
         $route_names = array();
         $this->instances[$route_appears] = array();
         // @todo - optimize this lookup by compiling or caching.
         foreach ($this->getDefinitions() as $plugin_id => $action_info) {
             if (in_array($route_appears, $action_info['appears_on'])) {
                 $plugin = $this->createInstance($plugin_id);
                 $route_names[] = $plugin->getRouteName();
                 $this->instances[$route_appears][$plugin_id] = $plugin;
             }
         }
         // Pre-fetch all the action route objects. This reduces the number of SQL
         // queries that would otherwise be triggered by the access manager.
         if (!empty($route_names)) {
             $this->routeProvider->getRoutesByNames($route_names);
         }
     }
     $links = array();
     /** @var $plugin \Drupal\Core\Menu\LocalActionInterface */
     foreach ($this->instances[$route_appears] as $plugin_id => $plugin) {
         $route_name = $plugin->getRouteName();
         $route_parameters = $plugin->getRouteParameters($this->routeMatch);
         $links[$plugin_id] = array('#theme' => 'menu_local_action', '#link' => array('title' => $this->getTitle($plugin), 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $plugin->getOptions($this->routeMatch)), '#access' => $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account), '#weight' => $plugin->getWeight());
     }
     return $links;
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:31,代码来源:LocalActionManager.php

示例9: menuLinkCheckAccess

 /**
  * Checks access for one menu link instance.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $instance
  *   The menu link instance.
  *
  * @return bool
  *   TRUE if the current user can access the link, FALSE otherwise.
  */
 protected function menuLinkCheckAccess(MenuLinkInterface $instance)
 {
     // Use the definition here since that's a lot faster than creating a Url
     // object that we don't need.
     $definition = $instance->getPluginDefinition();
     // 'url' should only be populated for external links.
     if (!empty($definition['url']) && empty($definition['route_name'])) {
         $access = TRUE;
     } else {
         $access = $this->accessManager->checkNamedRoute($definition['route_name'], $definition['route_parameters'], $this->account);
     }
     return $access;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:22,代码来源:DefaultMenuLinkTreeManipulators.php

示例10: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     switch ($operation) {
         case 'view':
             // There is no direct view.
             return AccessResult::neutral();
         case 'update':
             if (!$account->hasPermission('administer menu')) {
                 return AccessResult::neutral()->cachePerRole();
             } else {
                 // If there is a URL, this is an external link so always accessible.
                 $access = AccessResult::allowed()->cachePerRole()->cacheUntilEntityChanges($entity);
                 if (!$entity->getUrl()) {
                     // We allow access, but only if the link is accessible as well.
                     $link_access = $this->accessManager->checkNamedRoute($entity->getRouteName(), $entity->getRouteParameters(), $account, TRUE);
                     return $access->andIf($link_access);
                 }
                 return $access;
             }
         case 'delete':
             return AccessResult::allowedIf(!$entity->isNew() && $account->hasPermission('administer menu'))->cachePerRole()->cacheUntilEntityChanges($entity);
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:26,代码来源:MenuLinkContentAccessControlHandler.php

示例11: menuLinkCheckAccess

 /**
  * Checks access for one menu link instance.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $instance
  *   The menu link instance.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 protected function menuLinkCheckAccess(MenuLinkInterface $instance)
 {
     $access_result = NULL;
     if ($this->account->hasPermission('link to any page')) {
         $access_result = AccessResult::allowed();
     } else {
         $url = $instance->getUrlObject();
         // When no route name is specified, this must be an external link.
         if (!$url->isRouted()) {
             $access_result = AccessResult::allowed();
         } else {
             $access_result = $this->accessManager->checkNamedRoute($url->getRouteName(), $url->getRouteParameters(), $this->account, TRUE);
         }
     }
     return $access_result->cachePerPermissions();
 }
开发者ID:318io,项目名称:318-io,代码行数:25,代码来源:DefaultMenuLinkTreeManipulators.php

示例12: 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_name = $route_request->attributes->get(RouteObjectInterface::ROUTE_NAME);
             // Note that the parameters don't really matter here since we're
             // passing in the request which already has the upcast attributes.
             $parameters = array();
             $access = $this->accessManager->checkNamedRoute($route_name, $parameters, $this->currentUser, $route_request);
             if ($access) {
                 $title = $this->titleResolver->getTitle($route_request, $route_request->attributes->get(RouteObjectInterface::ROUTE_OBJECT));
             }
             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)));
                 }
                 // @todo Replace with a #type => link render element so that the alter
                 // hook can work with the actual data.
                 $links[] = $this->l($title, $route_request->attributes->get(RouteObjectInterface::ROUTE_NAME), $route_request->attributes->get('_raw_variables')->all(), array('html' => TRUE));
             }
         }
     }
     if ($path && $path != $front) {
         // Add the Home link, except for the front page.
         $links[] = $this->l($this->t('Home'), '<front>');
     }
     return array_reverse($links);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:49,代码来源:PathBasedBreadcrumbBuilder.php

示例13: getContextualLinksArrayByGroup

 /**
  * {@inheritdoc}
  */
 public function getContextualLinksArrayByGroup($group_name, array $route_parameters, array $metadata = array())
 {
     $links = array();
     $request = $this->requestStack->getCurrentRequest();
     foreach ($this->getContextualLinkPluginsByGroup($group_name) as $plugin_id => $plugin_definition) {
         /** @var $plugin \Drupal\Core\Menu\ContextualLinkInterface */
         $plugin = $this->createInstance($plugin_id);
         $route_name = $plugin->getRouteName();
         // Check access.
         if (!$this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account)) {
             continue;
         }
         $links[$plugin_id] = array('route_name' => $route_name, 'route_parameters' => $route_parameters, 'title' => $plugin->getTitle($request), 'weight' => $plugin->getWeight(), 'localized_options' => $plugin->getOptions(), 'metadata' => $metadata);
     }
     $this->moduleHandler->alter('contextual_links', $links, $group_name, $route_parameters);
     return $links;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:20,代码来源:ContextualLinkManager.php

示例14: menuLinkCheckAccess

 /**
  * Checks access for one menu link instance.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $instance
  *   The menu link instance.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 protected function menuLinkCheckAccess(MenuLinkInterface $instance)
 {
     $access_result = NULL;
     if ($this->account->hasPermission('link to any page')) {
         $access_result = AccessResult::allowed();
     } else {
         // Use the definition here since that's a lot faster than creating a Url
         // object that we don't need.
         $definition = $instance->getPluginDefinition();
         // 'url' should only be populated for external links.
         if (!empty($definition['url']) && empty($definition['route_name'])) {
             $access_result = AccessResult::allowed();
         } else {
             $access_result = $this->accessManager->checkNamedRoute($definition['route_name'], $definition['route_parameters'], $this->account, TRUE);
         }
     }
     return $access_result->cachePerPermissions();
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:27,代码来源:DefaultMenuLinkTreeManipulators.php

示例15: renderLink

 /**
  * {@inheritdoc}
  */
 protected function renderLink(EntityInterface $entity, ResultRow $values)
 {
     if (empty($entity)) {
         return;
     }
     // Check access when we pull up the user account so we know
     // if the user has made the contact page available.
     if (!$this->accessManager->checkNamedRoute('entity.user.contact_form', array('user' => $entity->id()), $this->currentUser())) {
         return;
     }
     $this->options['alter']['make_link'] = TRUE;
     $this->options['alter']['path'] = "user/{$entity->id()}/contact";
     $title = $this->t('Contact %user', array('%user' => $entity->name->value));
     $this->options['alter']['attributes'] = array('title' => $title);
     if (!empty($this->options['text'])) {
         return $this->options['text'];
     } else {
         return $title;
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:23,代码来源:ContactLink.php


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