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


PHP EntityInterface::isAnonymous方法代码示例

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


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

示例1: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\user\UserInterface $entity*/
     // The anonymous user's profile can neither be viewed, updated nor deleted.
     if ($entity->isAnonymous()) {
         return AccessResult::forbidden();
     }
     // Administrators can view/update/delete all user profiles.
     if ($account->hasPermission('administer users')) {
         return AccessResult::allowed()->cachePerRole();
     }
     switch ($operation) {
         case 'view':
             // Only allow view access if the account is active.
             if ($account->hasPermission('access user profiles') && $entity->isActive()) {
                 return AccessResult::allowed()->cachePerRole()->cacheUntilEntityChanges($entity);
             } else {
                 if ($account->id() == $entity->id()) {
                     return AccessResult::allowed()->cachePerUser();
                 }
             }
             break;
         case 'update':
             // Users can always edit their own account.
             return AccessResult::allowedIf($account->id() == $entity->id())->cachePerUser();
         case 'delete':
             // Users with 'cancel account' permission can cancel their own account.
             return AccessResult::allowedIf($account->id() == $entity->id() && $account->hasPermission('cancel account'))->cachePerRole()->cachePerUser();
     }
     // No opinion.
     return AccessResult::neutral();
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:35,代码来源:UserAccessControlHandler.php

示例2: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     /** @var \Drupal\user\UserInterface $entity*/
     // We don't treat the user label as privileged information, so this check
     // has to be the first one in order to allow labels for all users to be
     // viewed, including the special anonymous user.
     if ($operation === 'view label') {
         return AccessResult::allowed();
     }
     // The anonymous user's profile can neither be viewed, updated nor deleted.
     if ($entity->isAnonymous()) {
         return AccessResult::forbidden();
     }
     // Administrators can view/update/delete all user profiles.
     if ($account->hasPermission('administer users')) {
         return AccessResult::allowed()->cachePerPermissions();
     }
     switch ($operation) {
         case 'view':
             // Only allow view access if the account is active.
             if ($account->hasPermission('access user profiles') && $entity->isActive()) {
                 return AccessResult::allowed()->cachePerPermissions()->addCacheableDependency($entity);
             } elseif ($account->id() == $entity->id()) {
                 return AccessResult::allowed()->cachePerUser();
             }
             break;
         case 'update':
             // Users can always edit their own account.
             return AccessResult::allowedIf($account->id() == $entity->id())->cachePerUser();
         case 'delete':
             // Users with 'cancel account' permission can cancel their own account.
             return AccessResult::allowedIf($account->id() == $entity->id() && $account->hasPermission('cancel account'))->cachePerPermissions()->cachePerUser();
     }
     // No opinion.
     return AccessResult::neutral();
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:39,代码来源:UserAccessControlHandler.php


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