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


PHP AccessResult::allowedIfHasPermission方法代码示例

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


在下文中一共展示了AccessResult::allowedIfHasPermission方法的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: access

 /**
  * Checks access to the translation overview for the entity and bundle.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param string $entity_type_id
  *   The entity type ID.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(RouteMatchInterface $route_match, AccountInterface $account, $entity_type_id)
 {
     /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     $entity = $route_match->getParameter($entity_type_id);
     if ($entity && $entity->isTranslatable()) {
         // Get entity base info.
         $bundle = $entity->bundle();
         // Get entity access callback.
         $definition = $this->entityManager->getDefinition($entity_type_id);
         $translation = $definition->get('translation');
         $access_callback = $translation['content_translation']['access_callback'];
         $access = call_user_func($access_callback, $entity);
         if ($access->isAllowed()) {
             return $access;
         }
         // Check "translate any entity" permission.
         if ($account->hasPermission('translate any entity')) {
             return AccessResult::allowed()->cachePerPermissions()->inheritCacheability($access);
         }
         // Check per entity permission.
         $permission = "translate {$entity_type_id}";
         if ($definition->getPermissionGranularity() == 'bundle') {
             $permission = "translate {$bundle} {$entity_type_id}";
         }
         return AccessResult::allowedIfHasPermission($account, $permission)->inheritCacheability($access);
     }
     // No opinion.
     return AccessResult::neutral();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:42,代码来源:ContentTranslationOverviewAccess.php

示例3: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     if ($entity->getOwnerId() == $account->id()) {
         return AccessResult::allowedIfHasPermission($account, $operation . ' own ' . $entity->bundle() . ' entity');
     }
     return AccessResult::allowedIfHasPermission($account, $operation . ' any ' . $entity->bundle() . ' entity');
 }
开发者ID:jokas,项目名称:d8.dev,代码行数:10,代码来源:EckEntityAccessControlHandler.php

示例4: checkAccess

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    /** @var \Drupal\entityqueue\EntitySubqueueInterface $entity */
    switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'access content');
        break;

      case 'update':
        return AccessResult::allowedIfHasPermissions($account, ["update {$entity->bundle()} entityqueue", 'manipulate all entityqueues', 'administer entityqueue'], 'OR');
        break;

      case 'delete':
        $can_delete_subqueue = AccessResult::allowedIf(!$entity->getQueue()->getHandlerPlugin()->hasAutomatedSubqueues());

        $access_result = AccessResult
          ::allowedIfHasPermissions($account, ["delete {$entity->bundle()} entityqueue", 'manipulate all entityqueues', 'administer entityqueue'], 'OR')
          ->andIf($can_delete_subqueue);

        return $access_result;
        break;

      default:
        // No opinion.
        return AccessResult::neutral();
    }
  }
开发者ID:jkyto,项目名称:agolf,代码行数:29,代码来源:EntitySubqueueAccessControlHandler.php

示例5: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     if ($operation === 'view') {
         return AccessResult::allowedIfHasPermission($account, 'access content');
     }
     return parent::checkAccess($entity, $operation, $account);
 }
开发者ID:oddhill,项目名称:entity_layout,代码行数:10,代码来源:EntityLayoutAccess.php

示例6: checkCreateAccess

 /**
  * {@inheritdoc}
  *
  * Separate from the checkAccess because the entity does not yet exist, it
  * will be created during the 'add' process.
  */
 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL)
 {
     if ($entity_bundle) {
         return AccessResult::allowedIfHasPermission($account, 'create ' . $entity_bundle . ' rdf entity');
     }
     return AccessResult::allowedIfHasPermission($account, 'add rdf entity');
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:13,代码来源:RdfAccessControlHandler.php

示例7: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $filter_format, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\filter\FilterFormatInterface $filter_format */
     // All users are allowed to use the fallback filter.
     if ($operation == 'use') {
         if ($filter_format->isFallbackFormat()) {
             return AccessResult::allowed();
         } else {
             return AccessResult::allowedIfHasPermission($account, $filter_format->getPermissionName());
         }
     }
     // The fallback format may not be disabled.
     if ($operation == 'disable' && $filter_format->isFallbackFormat()) {
         return AccessResult::forbidden();
     }
     // We do not allow filter formats to be deleted through the UI, because that
     // would render any content that uses them unusable.
     if ($operation == 'delete') {
         return AccessResult::forbidden();
     }
     if (in_array($operation, array('disable', 'update'))) {
         return parent::checkAccess($filter_format, $operation, $langcode, $account);
     }
     // No opinion.
     return AccessResult::neutral();
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:FilterFormatAccessControlHandler.php

示例8: access

 /**
  * {@inheritdoc}
  */
 public function access($node, AccountInterface $account = NULL, $return_as_object = FALSE)
 {
     if ($node->hasField('simplenews_issue') && $node->simplenews_issue->target_id != NULL) {
         return AccessResult::allowedIfHasPermission($account, 'administer newsletters')->orIf(AccessResult::allowedIfHasPermission($account, 'send newsletter'));
     }
     return AccessResult::neutral();
 }
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:10,代码来源:StopIssue.php

示例9: checkCreateAccess

 /**
  * {@inheritdoc}
  */
 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL)
 {
     $installed_translators = $this->translatorManager->getLabels();
     if (empty($installed_translators)) {
         return AccessResult::forbidden();
     }
     return AccessResult::allowedIfHasPermission($account, 'administer tmgmt');
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:11,代码来源:TranslatorAccessControlHandler.php

示例10: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     $access = parent::checkAccess($entity, $operation, $account);
     if ($operation === 'view') {
         $access = $access->orIf(AccessResult::allowedIfHasPermission($account, 'access ' . $entity->getEntityTypeId()));
     }
     return $access;
 }
开发者ID:heddn,项目名称:content_entity_base,代码行数:11,代码来源:EntityBaseAccessControlHandler.php

示例11: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     switch ($operation) {
         case 'delete':
             return AccessResult::allowedIf($account->hasPermission('administer feeds') && !$entity->isLocked());
         default:
             return AccessResult::allowedIfHasPermission($account, 'administer feeds');
     }
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:12,代码来源:FeedTypeAccessControlHandler.php

示例12: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     $admin_access = parent::checkAccess($entity, $operation, $account);
     // Allow view with other permission.
     if ($operation === 'view') {
         return AccessResult::allowedIfHasPermission($account, 'view moderation states')->orIf($admin_access);
     }
     return $admin_access;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:12,代码来源:ModerationStateAccessControlHandler.php

示例13: access

 /**
  * Access callback; check if the module is configured.
  *
  * This function does not actually check whether Mollom keys are valid for the
  * site, but just if the keys have been entered.
  *
  * @param $permission
  *   An optional permission string to check with \Drupal::currentUser()->hasPermission().
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 function access($permission = FALSE)
 {
     $configured = \Drupal::config('mollom.settings')->get('keys.public') && \Drupal::config('mollom.settings')->get('keys.private');
     if ($configured && $permission) {
         return AccessResult::allowedIfHasPermission($permission, \Drupal::currentUser());
     } else {
         return AccessResult::allowedIf($configured);
     }
 }
开发者ID:ABaldwinHunter,项目名称:durhamatletico-cms,代码行数:21,代码来源:DefaultController.php

示例14: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
   switch ($operation) {
     case 'view':
     case 'update':
     case 'delete':
       return AccessResult::allowedIfHasPermission($account, 'administer pdfs');
     default:
       return AccessResult::neutral();
   }
 }
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:13,代码来源:FillPdfFormAccessControlHandler.php

示例15: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     switch ($operation) {
         case 'view':
             return AccessResult::allowedIfHasPermission($account, 'access content');
             break;
         default:
             return parent::checkAccess($entity, $operation, $account);
             break;
     }
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:14,代码来源:VocabularyAccessControlHandler.php


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