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

PHP Session\AccountInterface类代码示例

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

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



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

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


示例2: access

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


示例3: defaultAccess

 /**
  * {@inheritdoc}
  */
 public function defaultAccess($operation = 'view', AccountInterface $account = NULL)
 {
     if ($operation == 'view') {
         return TRUE;
     }
     return $account->hasPermission('create url aliases') || $account->hasPermission('administer url aliases');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:10,代码来源:PathFieldItemList.php


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


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


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


示例7: generate

 /**
  * {@inheritdoc}
  *
  * Cached by role, invalidated whenever permissions change.
  */
 public function generate(AccountInterface $account)
 {
     // User 1 is the super user, and can always access all permissions. Use a
     // different, unique identifier for the hash.
     if ($account->id() == 1) {
         return $this->hash('is-super-user');
     }
     $sorted_roles = $account->getRoles();
     sort($sorted_roles);
     $role_list = implode(',', $sorted_roles);
     $cid = "user_permissions_hash:{$role_list}";
     if ($static_cache = $this->static->get($cid)) {
         return $static_cache->data;
     } else {
         $tags = Cache::buildTags('config:user.role', $sorted_roles, '.');
         if ($cache = $this->cache->get($cid)) {
             $permissions_hash = $cache->data;
         } else {
             $permissions_hash = $this->doGenerate($sorted_roles);
             $this->cache->set($cid, $permissions_hash, Cache::PERMANENT, $tags);
         }
         $this->static->set($cid, $permissions_hash, Cache::PERMANENT, $tags);
     }
     return $permissions_hash;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:PermissionsHashGenerator.php


示例8: access

 /**
  * Checks translation access for the entity and operation on the given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param string $source
  *   (optional) For a create operation, the language code of the source.
  * @param string $target
  *   (optional) For a create operation, the language code of the translation.
  * @param string $language
  *   (optional) For an update or delete operation, the language code of the
  *   translation being updated or deleted.
  * @param string $entity_type_id
  *   (optional) The entity type ID.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $entity_type_id = NULL)
 {
     /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     if ($entity = $route_match->getParameter($entity_type_id)) {
         if ($account->hasPermission('translate any entity')) {
             return AccessResult::allowed()->cachePerRole();
         }
         $operation = $route->getRequirement('_access_content_translation_manage');
         /* @var \Drupal\content_translation\ContentTranslationHandlerInterface $handler */
         $handler = $this->entityManager->getHandler($entity->getEntityTypeId(), 'translation');
         // Load translation.
         $translations = $entity->getTranslationLanguages();
         $languages = $this->languageManager->getLanguages();
         switch ($operation) {
             case 'create':
                 $source_language = $this->languageManager->getLanguage($source) ?: $entity->language();
                 $target_language = $this->languageManager->getLanguage($target) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 $is_new_translation = $source_language->getId() != $target_language->getId() && isset($languages[$source_language->getId()]) && isset($languages[$target_language->getId()]) && !isset($translations[$target_language->getId()]);
                 return AccessResult::allowedIf($is_new_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation));
             case 'update':
             case 'delete':
                 $language = $this->languageManager->getLanguage($language) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 $has_translation = isset($languages[$language->getId()]) && $language->getId() != $entity->getUntranslated()->language()->getId() && isset($translations[$language->getId()]);
                 return AccessResult::allowedIf($has_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation));
         }
     }
     // No opinion.
     return AccessResult::neutral();
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:51,代码来源:ContentTranslationManageAccessCheck.php


示例9: access

 /**
  * Checks access to the given user's contact page.
  *
  * @param \Drupal\user\UserInterface $user
  *   The user being contacted.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(UserInterface $user, AccountInterface $account)
 {
     $contact_account = $user;
     // Anonymous users cannot have contact forms.
     if ($contact_account->isAnonymous()) {
         return static::DENY;
     }
     // Users may not contact themselves.
     if ($account->id() == $contact_account->id()) {
         return static::DENY;
     }
     // User administrators should always have access to personal contact forms.
     if ($account->hasPermission('administer users')) {
         return static::ALLOW;
     }
     // If requested user has been blocked, do not allow users to contact them.
     if ($contact_account->isBlocked()) {
         return static::DENY;
     }
     // If the requested user has disabled their contact form, do not allow users
     // to contact them.
     $account_data = $this->userData->get('contact', $contact_account->id(), 'enabled');
     if (isset($account_data) && empty($account_data)) {
         return static::DENY;
     } else {
         if (!$this->configFactory->get('contact.settings')->get('user_default_enabled')) {
             return static::DENY;
         }
     }
     return $account->hasPermission('access user contact forms') ? static::ALLOW : static::DENY;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:42,代码来源:ContactPageAccess.php


示例10: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     if ($operation == 'delete' && $entity->getFieldStorageDefinition()->isLocked()) {
         return FALSE;
     }
     return $account->hasPermission('administer ' . $entity->entity_type . ' fields');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:10,代码来源:FieldInstanceConfigAccessController.php


示例11: loadMultipleByUser

 /**
  * {@inheritdoc}
  */
 public function loadMultipleByUser(AccountInterface $account, $profile_type) {
   return $this->loadByProperties([
       'uid' => $account->id(),
       'type' => $profile_type,
       'status' => PROFILE_ACTIVE,
     ]);
 }
开发者ID:housineali,项目名称:drpl8_dv,代码行数:10,代码来源:ProfileStorage.php


示例12: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     if ($account->hasPermission('administer tmgmt')) {
         // Administrators can do everything.
         return AccessResult::allowed()->cachePerPermissions();
     }
     switch ($operation) {
         case 'view':
         case 'update':
             return AccessResult::allowedIfHasPermission($account, 'create translation jobs')->orIf(AccessResult::allowedIfHasPermission($account, 'accept translation jobs'));
             break;
         case 'delete':
             // Only administrators can delete jobs.
             return AccessResult::forbidden();
             break;
             // Custom operations.
         // Custom operations.
         case 'submit':
             return AccessResult::allowedIfHasPermission($account, 'submit translation jobs');
             break;
         case 'accept':
             return AccessResult::allowedIfHasPermission($account, 'accept translation jobs');
             break;
         case 'abort':
         case 'resubmit':
             return AccessResult::allowedIfHasPermission($account, 'submit translation jobs');
             break;
     }
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:32,代码来源:JobAccessControlHandler.php


示例13: access

 /**
  * Checks access to the given user's contact page.
  *
  * @param \Drupal\user\UserInterface $user
  *   The user being contacted.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(UserInterface $user, AccountInterface $account)
 {
     $contact_account = $user;
     // Anonymous users cannot have contact forms.
     if ($contact_account->isAnonymous()) {
         return AccessResult::forbidden();
     }
     // Users may not contact themselves.
     if ($account->id() == $contact_account->id()) {
         return AccessResult::forbidden()->cachePerUser();
     }
     // User administrators should always have access to personal contact forms.
     $access = AccessResult::neutral()->cachePerRole();
     $permission_access = AccessResult::allowedIfHasPermission($account, 'administer users');
     if ($permission_access->isAllowed()) {
         return $access->orIf($permission_access);
     }
     // If requested user has been blocked, do not allow users to contact them.
     $access->cacheUntilEntityChanges($contact_account);
     if ($contact_account->isBlocked()) {
         return $access;
     }
     // If the requested user has disabled their contact form, do not allow users
     // to contact them.
     $account_data = $this->userData->get('contact', $contact_account->id(), 'enabled');
     if (isset($account_data) && empty($account_data)) {
         return $access;
     } else {
         if (!$this->configFactory->get('contact.settings')->get('user_default_enabled')) {
             return $access;
         }
     }
     return $access->orIf(AccessResult::allowedIfHasPermission($account, 'access user contact forms'));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:45,代码来源:ContactPageAccess.php


示例14: blockAccess

 /**
  * {@inheritdoc}
  */
 protected function blockAccess(AccountInterface $account)
 {
     $route_name = $this->routeMatch->getRouteName();
     if ($account->isAnonymous() && !in_array($route_name, array('user.login', 'user.logout'))) {
         return AccessResult::allowed()->addCacheContexts(['route.name', 'user.roles:anonymous']);
     }
     return AccessResult::forbidden();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:11,代码来源:UserLoginBlock.php


示例15: access

 /**
  * {@inheritdoc}
  */
 public function access(Route $route, Request $request, AccountInterface $account)
 {
     // Suppress notices when on other pages when menu system still checks access.
     $name = $request->attributes->get('name');
     $token = $request->query->get('token');
     $destination = $request->query->get('destination');
     return $account->hasPermission('switch users') && $this->csrfToken->validate($token, "devel/switch/{$name}|" . $destination, TRUE) ? static::ALLOW : static::DENY;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:11,代码来源:SwitchAccess.php


示例16: access

 /**
  * {@inheritdoc}
  */
 public function access(AccountInterface $account)
 {
     foreach ($this->permissions as $permission) {
         if ($account->hasPermission($permission)) {
             return TRUE;
         }
     }
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:11,代码来源:ViewJobAccess.php


示例17: onRespond

 /**
  * Redirects login attempts on already-logged-in session to the destination.
  */
 public function onRespond(FilterResponseEvent $event)
 {
     // Return early in most cases.
     if ($event->getRequest()->getMethod() !== 'POST') {
         return;
     }
     if (!$this->currentUser->isAuthenticated()) {
         return;
     }
     if (!$event->isMasterRequest()) {
         return;
     }
     if (!$event->getRequest()->query->has('destination')) {
         return;
     }
     if ($event->getResponse() instanceof RedirectResponse) {
         return;
     }
     // There has to be a better way to figure out if we landed on the 403/404 page.
     $page_403 = $this->configFactory->get('system.site')->get('page.403');
     $page_404 = $this->configFactory->get('system.site')->get('page.404');
     $path = $this->currentPath->getPath();
     $route = $this->currentRouteMatch->getRouteName();
     if ($route == 'system.403' || $page_403 && $path == $page_403 || $route == 'system.404' || $page_404 && $path == $page_404) {
         // RedirectResponseSubscriber will convert to absolute URL for us.
         $event->setResponse(new RedirectResponse($this->redirectDestination->get(), RedirectResponse::HTTP_SEE_OTHER));
     }
 }
开发者ID:Wylbur,项目名称:gj,代码行数:31,代码来源:SecureLoginResponseSubscriber.php


示例18: onKernelRequestMaintenance

 /**
  * Determine whether the page is configured to be offline.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The event to process.
  */
 public function onKernelRequestMaintenance(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $route_match = RouteMatch::createFromRequest($request);
     $path = $request->attributes->get('_system_path');
     if ($this->maintenanceMode->applies($route_match)) {
         // If the site is offline, log out unprivileged users.
         if ($this->account->isAuthenticated() && !$this->maintenanceMode->exempt($this->account)) {
             user_logout();
             // Redirect to homepage.
             $event->setResponse(new RedirectResponse($this->url('<front>', [], ['absolute' => TRUE])));
             return;
         }
     }
     if ($this->account->isAuthenticated()) {
         if ($path == 'user/login') {
             // If the user is already logged in, redirect to their profile page.
             $event->setResponse($this->redirect('entity.user.canonical', ['user' => $this->account->id()]));
             return;
         }
         if ($path == 'user/register') {
             // If the user is already registered, redirect to their edit page.
             $event->setResponse(new RedirectResponse($this->url('entity.user.edit_form', ['user' => $this->account->id()], ['absolute' => TRUE])));
             return;
         }
     }
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:33,代码来源:MaintenanceModeSubscriber.php


示例19: testMetatag

 /**
  * Tests adding and editing values using metatag.
  */
 public function testMetatag()
 {
     // Create a test entity.
     $edit = ['name[0][value]' => 'Barfoo', 'user_id[0][target_id]' => 'foo (' . $this->adminUser->id() . ')'];
     $this->drupalPostForm('entity_test/add', $edit, t('Save'));
     $entities = entity_load_multiple_by_properties('entity_test', ['name' => 'Barfoo']);
     $this->assertEqual(1, count($entities), 'Entity was saved');
     $entity = reset($entities);
     // Update the Global defaults and test them.
     $values = array('keywords' => 'Purple monkey dishwasher');
     $this->drupalPostForm('admin/structure/metatag_defaults/global', $values, 'Save');
     $this->assertText('Saved the Global Metatag defaults.');
     $this->drupalGet('entity_test/' . $entity->id());
     $elements = $this->cssSelect('meta[name=keywords]');
     $this->assertTrue(count($elements) === 1, 'Found keywords metatag from defaults');
     $this->assertEqual((string) $elements[0]['content'], $values['keywords'], 'Default keywords applied');
     // Tests metatags with urls work.
     $edit = ['name[0][value]' => 'UrlTags', 'user_id[0][target_id]' => 'foo (' . $this->adminUser->id() . ')', 'field_metatag[0][open_graph][og_url]' => 'http://example.com/foo.html'];
     $this->drupalPostForm('entity_test/add', $edit, t('Save'));
     $entities = entity_load_multiple_by_properties('entity_test', ['name' => 'UrlTags']);
     $this->assertEqual(1, count($entities), 'Entity was saved');
     $entity = reset($entities);
     $this->drupalGet('entity_test/' . $entity->id());
     $elements = $this->cssSelect("meta[property='og:url']");
     $this->assertTrue(count($elements) === 1, 'Found keywords metatag from defaults');
     $this->assertEqual((string) $elements[0]['content'], $edit['field_metatag[0][open_graph][og_url]']);
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:30,代码来源:MetatagFieldTest.php


示例20: log

 /**
  * {@inheritdoc}
  */
 public function log($level, $message, array $context = array())
 {
     // Merge in defaults.
     $context += array('channel' => $this->channel, 'link' => '', 'user' => NULL, 'uid' => 0, 'request_uri' => '', 'referer' => '', 'ip' => '', 'timestamp' => time());
     // Some context values are only available when in a request context.
     if ($this->requestStack && ($request = $this->requestStack->getCurrentRequest())) {
         $context['request_uri'] = $request->getUri();
         $context['referer'] = $request->headers->get('Referer', '');
         $context['ip'] = $request->getClientIP();
         try {
             if ($this->currentUser) {
                 $context['user'] = $this->currentUser;
                 $context['uid'] = $this->currentUser->id();
             }
         } catch (\Exception $e) {
             // An exception might be thrown if the database connection is not
             // available or due to another unexpected reason. It is more important
             // to log the error that we already have so any additional exceptions
             // are ignored.
         }
     }
     if (is_string($level)) {
         // Convert to integer equivalent for consistency with RFC 5424.
         $level = $this->levelTranslation[$level];
     }
     // Call all available loggers.
     foreach ($this->sortLoggers() as $logger) {
         $logger->log($level, $message, $context);
     }
 }
开发者ID:Wylbur,项目名称:gj,代码行数:33,代码来源:LoggerChannel.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Site\Settings类代码示例发布时间:2022-05-23
下一篇:
PHP Routing\UrlGeneratorInterface类代码示例发布时间: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