• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Access\AccessResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: access

 /**
  * {@inheritdoc}
  */
 public function access(Route $route, AccountInterface $account, NodeInterface $node = NULL)
 {
     if ($node->bundle() && \Drupal::config('webform.settings')->get('node_' . $node->bundle())) {
         return AccessResult::allowed();
     }
     return AccessResult::forbidden();
 }
开发者ID:Progressable,项目名称:openway8,代码行数:10,代码来源:WebformNodeAccessCheck.php


示例3: checkConfigurationAccess

 /**
  * Checks configuration permission.
  *
  * @param AccountInterface $account
  *   (optional) The user for which to check access, or NULL to check access
  *   for the current user. Defaults to NULL.
  * @param bool $return_as_object
  *   (optional) Defaults to FALSE.
  *
  * @return bool|\Drupal\Core\Access\AccessResultInterface
  *   The access result. Returns a boolean if $return_as_object is FALSE (this
  *   is the default) and otherwise an AccessResultInterface object.
  *   When a boolean is returned, the result of AccessInterface::isAllowed() is
  *   returned, i.e. TRUE means access is explicitly allowed, FALSE means
  *   access is either explicitly forbidden or "no opinion".
  */
 public function checkConfigurationAccess(AccountInterface $account = NULL, $return_as_object = FALSE)
 {
     if (!$account) {
         $account = \Drupal::currentUser();
     }
     // We treat these as our "super-user" accesses.  We let the reaction
     // rule and component permissions control the main admin UI.
     $admin_perms = ['administer rules', 'bypass rules access'];
     $access = FALSE;
     foreach ($admin_perms as $perm) {
         if ($account->hasPermission($perm)) {
             $access = TRUE;
             break;
         }
     }
     if (!$access) {
         // See if the plugin has a configuration_access annotation.
         $definition = $this->getPluginDefinition();
         if (!empty($definition['configure_permissions']) && is_array($definition['configure_permissions'])) {
             foreach ($definition['configure_permissions'] as $perm) {
                 if ($account->hasPermission($perm)) {
                     $access = TRUE;
                     break;
                 }
             }
         }
     }
     if ($return_as_object) {
         return $access ? AccessResult::allowed() : AccessResult::neutral();
     }
     return $access;
 }
开发者ID:Progressable,项目名称:openway8,代码行数:48,代码来源:ConfigurationAccessControlTrait.php


示例4: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     if ($operation === 'view') {
         return AccessResult::allowed();
     }
     return parent::checkAccess($entity, $operation, $account);
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:10,代码来源:BlockContentAccessControlHandler.php


示例5: access

 /**
  * Grants access only to UID 1.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(AccountInterface $account)
 {
     if ($account->id() == 1) {
         return AccessResult::allowed()->addCacheContexts(['user']);
     }
     return AccessResult::forbidden()->addCacheContexts(['user']);
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:16,代码来源:Uid1OnlyAccess.php


示例6: access

 /**
  * Checks access to create an entity of any bundle for the given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parameterized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $entity_type_id = $route->getRequirement($this->requirementsKey);
     $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
     $access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type_id);
     // In case there is no "bundle" entity key, check create access with no
     // bundle specified.
     if (!$entity_type->hasKey('bundle')) {
         return $access_control_handler->createAccess(NULL, $account, [], TRUE);
     }
     $access = AccessResult::neutral();
     $bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));
     // Include list cache tag as access might change if more bundles are added.
     if ($entity_type->getBundleEntityType()) {
         $access->addCacheTags($this->entityTypeManager->getDefinition($entity_type->getBundleEntityType())->getListCacheTags());
         // Check if the user is allowed to create new bundles. If so, allow
         // access, so the add page can show a link to create one.
         // @see \Drupal\Core\Entity\Controller\EntityController::addPage()
         $bundle_access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type->getBundleEntityType());
         $access = $access->orIf($bundle_access_control_handler->createAccess(NULL, $account, [], TRUE));
         if ($access->isAllowed()) {
             return $access;
         }
     }
     // Check whether an entity of any bundle may be created.
     foreach ($bundles as $bundle) {
         $access = $access->orIf($access_control_handler->createAccess($bundle, $account, [], TRUE));
         // In case there is a least one bundle user can create entities for,
         // access is allowed.
         if ($access->isAllowed()) {
             break;
         }
     }
     return $access;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:48,代码来源:EntityCreateAnyAccessCheck.php


示例7: access

 /**
  * Checks Quick Edit access to the field.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity containing the field.
  * @param string $field_name
  *   The field name.
  * @param string $langcode
  *   The langcode.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  *
  * @todo Use the $account argument: https://www.drupal.org/node/2266809.
  */
 public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account)
 {
     if (!$this->validateRequestAttributes($entity, $field_name, $langcode)) {
         return AccessResult::forbidden();
     }
     return $this->accessEditEntityField($entity, $field_name);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:24,代码来源:EditEntityFieldAccessCheck.php


示例8: createAssetReleaseAccess

 /**
  * Handles access to the rdf_entity proposal form.
  *
  * @param \Drupal\rdf_entity\RdfEntityTypeInterface $rdf_type
  *   The RDF entity type for which the proposal form is built.
  *
  * @return \Drupal\Core\Access\AccessResult
  *   The access result object.
  */
 public function createAssetReleaseAccess(RdfEntityTypeInterface $rdf_type)
 {
     if (!in_array($rdf_type->id(), ['collection', 'solution'])) {
         return AccessResult::forbidden();
     }
     return AccessResult::allowedIf($this->currentUser()->hasPermission("propose {$rdf_type->id()} rdf entity"));
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:16,代码来源:JoinupController.php


示例9: 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


示例10: accessLibrary

 /**
  * Limit access to the Library between 9:00 and 18:30.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  */
 public function accessLibrary(AccountInterface $account)
 {
     if (time() >= strtotime('today 9:00') && time() <= strtotime('today 18:30')) {
         return AccessResult::allowed();
     }
     return AccessResult::forbidden();
 }
开发者ID:Happyculture,项目名称:exercices,代码行数:12,代码来源:AlexandrieAccess.php


示例11: defaultAccess

 /**
  * {@inheritdoc}
  */
 public function defaultAccess($operation = 'view', AccountInterface $account = NULL)
 {
     if ($operation == 'view') {
         return AccessResult::allowed();
     }
     return AccessResult::allowedIfHasPermissions($account, ['create url aliases', 'administer url aliases'], 'OR')->cachePerPermissions();
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:PathFieldItemList.php


示例12: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     /** @var \Drupal\file\FileInterface $entity */
     if ($operation == 'download' || $operation == 'view') {
         if (\Drupal::service('file_system')->uriScheme($entity->getFileUri()) === 'public') {
             // Always allow access to file in public file system.
             return AccessResult::allowed();
         } elseif ($references = $this->getFileReferences($entity)) {
             foreach ($references as $field_name => $entity_map) {
                 foreach ($entity_map as $referencing_entity_type => $referencing_entities) {
                     /** @var \Drupal\Core\Entity\EntityInterface $referencing_entity */
                     foreach ($referencing_entities as $referencing_entity) {
                         $entity_and_field_access = $referencing_entity->access('view', $account, TRUE)->andIf($referencing_entity->{$field_name}->access('view', $account, TRUE));
                         if ($entity_and_field_access->isAllowed()) {
                             return $entity_and_field_access;
                         }
                     }
                 }
             }
         } elseif ($entity->getOwnerId() == $account->id()) {
             // This case handles new nodes, or detached files. The user who uploaded
             // the file can always access if it's not yet used.
             return AccessResult::allowed();
         }
     }
     // No opinion.
     return AccessResult::neutral();
 }
开发者ID:318io,项目名称:318-io,代码行数:31,代码来源:FileAccessControlHandler.php


示例13: blockAccess

 /**
  * {@inheritdoc}
  */
 protected function blockAccess(AccountInterface $account)
 {
     if ($account->hasPermission('search content')) {
         return AccessResult::allowed();
     }
     return AccessResult::forbidden();
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:10,代码来源:CustomSearchBlock.php


示例14: access

 public function access(AccountInterface $account)
 {
     if (!$account->id() == 1) {
         return AccessResult::forbidden();
     }
     return AccessResult::allowed();
 }
开发者ID:ttournie,项目名称:drupal8_tuto,代码行数:7,代码来源:HelloWorldAccessCheck.php


示例15: 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


示例16: access

 /**
  * Checks that there is a forward revision available.
  *
  * This checker assumes the presence of an '_entity_access' requirement key
  * in the same form as used by EntityAccessCheck.
  *
  * @see EntityAccessCheck.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match)
 {
     // This tab should not show up period unless there's a reason to show it.
     // @todo Do we need any extra cache tags here?
     $entity = $this->loadEntity($route, $route_match);
     return $this->moderationInfo->hasForwardRevision($entity) ? AccessResult::allowed()->addCacheableDependency($entity) : AccessResult::forbidden()->addCacheableDependency($entity);
 }
开发者ID:tedbow,项目名称:scheduled-updates-demo,代码行数:23,代码来源:LatestRevisionCheck.php


示例17: testAccess

 /**
  * Tests the method for checking access to routes.
  *
  * @dataProvider providerTestAccess
  */
 public function testAccess($entity_bundle, $requirement, $access, $expected, $expect_permission_context = TRUE)
 {
     // Set up the access result objects for allowing or denying access.
     $access_result = $access ? AccessResult::allowed()->cachePerPermissions() : AccessResult::neutral()->cachePerPermissions();
     $expected_access_result = $expected ? AccessResult::allowed() : AccessResult::neutral();
     if ($expect_permission_context) {
         $expected_access_result->cachePerPermissions();
     }
     $entity_manager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
     // Don't expect a call to the access control handler when we have a bundle
     // argument requirement but no bundle is provided.
     if ($entity_bundle || strpos($requirement, '{') === FALSE) {
         $access_control_handler = $this->getMock('Drupal\\Core\\Entity\\EntityAccessControlHandlerInterface');
         $access_control_handler->expects($this->once())->method('createAccess')->with($entity_bundle)->will($this->returnValue($access_result));
         $entity_manager->expects($this->any())->method('getAccessControlHandler')->will($this->returnValue($access_control_handler));
     }
     $applies_check = new EntityCreateAccessCheck($entity_manager);
     $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock();
     $route->expects($this->any())->method('getRequirement')->with('_entity_create_access')->will($this->returnValue($requirement));
     $raw_variables = new ParameterBag();
     if ($entity_bundle) {
         $raw_variables->set('bundle_argument', $entity_bundle);
     }
     $route_match = $this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface');
     $route_match->expects($this->any())->method('getRawParameters')->will($this->returnValue($raw_variables));
     $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $this->assertEquals($expected_access_result, $applies_check->access($route, $route_match, $account));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:33,代码来源:EntityCreateAccessCheckTest.php


示例18: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     /** @var \Drupal\crm_core_contact\Entity\ContactType $entity */
     // First check permission.
     if (parent::checkAccess($entity, $operation, $account)->isForbidden()) {
         return AccessResult::forbidden();
     }
     switch ($operation) {
         case 'enable':
             // Only disabled contact type can be enabled.
             return AccessResult::allowedIf(!$entity->status());
         case 'disable':
             return AccessResult::allowedIf($entity->status());
         case 'delete':
             // If contact instance of this contact type exist, you can't delete it.
             $results = \Drupal::entityQuery('crm_core_contact')->condition('type', $entity->id())->execute();
             return AccessResult::allowedIf(empty($results));
             // @todo Which is it?
         // @todo Which is it?
         case 'edit':
         case 'update':
             // If the contact type is locked, you can't edit it.
             return AccessResult::allowed();
     }
 }
开发者ID:jasonruyle,项目名称:crm_core,代码行数:28,代码来源:ContactTypeAccessControlHandler.php


示例19: 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


示例20: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
     $cache_contexts_manager->assertValidTokens()->willReturn(TRUE);
     $cache_contexts_manager->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     $this->viewer = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->viewer->expects($this->any())->method('hasPermission')->will($this->returnValue(FALSE));
     $this->viewer->expects($this->any())->method('id')->will($this->returnValue(1));
     $this->owner = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->owner->expects($this->any())->method('hasPermission')->will($this->returnValueMap(array(array('administer users', FALSE), array('change own username', TRUE))));
     $this->owner->expects($this->any())->method('id')->will($this->returnValue(2));
     $this->admin = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->admin->expects($this->any())->method('hasPermission')->will($this->returnValue(TRUE));
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->accessControlHandler = new UserAccessControlHandler($entity_type);
     $module_handler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $module_handler->expects($this->any())->method('getImplementations')->will($this->returnValue(array()));
     $this->accessControlHandler->setModuleHandler($module_handler);
     $this->items = $this->getMockBuilder('Drupal\\Core\\Field\\FieldItemList')->disableOriginalConstructor()->getMock();
     $this->items->expects($this->any())->method('defaultAccess')->will($this->returnValue(AccessResult::allowed()));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:28,代码来源:UserAccessControlHandlerTest.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Ajax\AjaxResponse类代码示例发布时间:2022-05-23
下一篇:
PHP Access\AccessManagerInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap