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


PHP AccountInterface::hasPermission方法代码示例

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


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

示例1: render

 /**
  * {@inheritdoc}
  */
 function render(ResultRow $values)
 {
     // Ensure Disqus comments are available on the entity and user has access to edit this entity.
     $entity = $this->getEntity($values);
     if (!$entity) {
         return;
     }
     $field = $this->disqusManager->getFields($entity->getEntityTypeId());
     if (!$entity->hasField(key($field))) {
         return;
     }
     if ($entity->get(key($field))->status && $this->currentUser->hasPermission('view disqus comments')) {
         // Build a renderable array for the link.
         $links['disqus_comments_num'] = array('title' => t('Comments'), 'url' => $entity->urlInfo(), 'fragment' => 'disqus_thread', 'attributes' => array('data-disqus-identifier' => "{$entity->getEntityTypeId()}/{$entity->id()}"));
         $content = array('#theme' => 'links', '#links' => $links, '#attributes' => array('class' => array('links', 'inline')));
         /**
          * This attaches disqus.js specified in the disqus.libraries.yml file,
          * which will look for the DOM variable disqusComments which is set below.
          * When found, the disqus javascript api replaces the html element with
          * the attribute: "data-disqus-identifier" and replaces the element with
          * the number of comments on the entity.
          */
         $content['#attached']['library'][] = 'disqus/disqus';
         $content['#attached']['drupalSettings']['disqusComments'] = $this->config->get('disqus_domain');
         return $content;
     }
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:30,代码来源:DisqusCommentCount.php

示例2: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->configFactory->get('examples.cron');
     $form['status'] = ['#type' => 'details', '#title' => $this->t('Cron status information'), '#open' => TRUE];
     $form['status']['intro'] = ['#type' => 'item', '#markup' => $this->t('The cron example demonstrates hook_cron() and hook_queue_info() processing. If you have administrative privileges you can run cron from this page and see the results.')];
     $next_execution = $config->get('next_execution');
     $next_execution = !empty($next_execution) ? $next_execution : REQUEST_TIME;
     $args = ['%time' => date_iso8601($config->get('next_execution')), '%seconds' => $next_execution - REQUEST_TIME];
     $form['status']['last'] = ['#type' => 'item', '#markup' => $this->t('cron_example_cron() will next execute the first time cron runs after %time (%seconds seconds from now)', $args)];
     if ($this->currentUser->hasPermission('administer site configuration')) {
         $form['cron_run'] = ['#type' => 'details', '#title' => $this->t('Run cron manually'), '#open' => TRUE];
         $form['cron_run']['cron_reset'] = ['#type' => 'checkbox', '#title' => $this->t('Run cron_example\'s cron regardless of whether interval has expired.'), '#default_value' => FALSE];
         $form['cron_run']['cron_trigger']['actions'] = ['#type' => 'actions'];
         $form['cron_run']['cron_trigger']['actions']['sumbit'] = ['#type' => 'submit', '#value' => $this->t('Run cron now'), '#submit' => [[$this, 'cronRun']]];
     }
     $form['cron_queue_setup'] = ['#type' => 'details', '#title' => $this->t('Cron queue setup (for hook_cron_queue_info(), etc.)'), '#open' => TRUE];
     $queue_1 = $this->queue->get('cron_example_queue_1');
     $queue_2 = $this->queue->get('cron_example_queue_2');
     $args = ['%queue_1' => $queue_1->numberOfItems(), '%queue_2' => $queue_2->numberOfItems()];
     $form['cron_queue_setup']['current_cron_queue_status'] = ['#type' => 'item', '#markup' => $this->t('There are currently %queue_1 items in queue 1 and %queue_2 items in queue 2', $args)];
     $form['cron_queue_setup']['num_items'] = ['#type' => 'select', '#title' => $this->t('Number of items to add to queue'), '#options' => array_combine([1, 5, 10, 100, 1000], [1, 5, 10, 100, 1000]), '#default_value' => 5];
     $form['cron_queue_setup']['queue'] = ['#type' => 'radios', '#title' => $this->t('Queue to add items to'), '#options' => ['cron_example_queue_1' => $this->t('Queue 1'), 'cron_example_queue_2' => $this->t('Queue 2')], '#default_value' => 'cron_example_queue_1'];
     $form['cron_queue_setup']['actions'] = ['#type' => 'actions'];
     $form['cron_queue_setup']['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Add jobs to queue'), '#submit' => [[$this, 'addItems']]];
     $form['configuration'] = ['#type' => 'details', '#title' => $this->t('Configuration of cron_example_cron()'), '#open' => TRUE];
     $form['configuration']['cron_example_interval'] = ['#type' => 'select', '#title' => $this->t('Cron interval'), '#description' => $this->t('Time after which cron_example_cron will respond to a processing request.'), '#default_value' => $config->get('interval'), '#options' => [60 => $this->t('1 minute'), 300 => $this->t('5 minutes'), 3600 => $this->t('1 hour'), 86400 => $this->t('1 day')]];
     return parent::buildForm($form, $form_state);
 }
开发者ID:seongbae,项目名称:drumo-distribution,代码行数:31,代码来源:CronExampleForm.php

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

示例4: checkAccess

 protected function checkAccess(ContentEntityInterface $entity, AccountInterface $account, $operation = 'view')
 {
     $entity_type = $entity->getEntityType();
     $entity_type_id = $entity->getEntityTypeId();
     $entity_access = $this->entityTypeManager->getAccessControlHandler($entity_type_id);
     /** @var \Drupal\Core\Entity\EntityStorageInterface $entity_storage */
     $entity_storage = $this->entityTypeManager->getStorage($entity_type_id);
     $map = ['view' => "view all {$entity_type_id} revisions", 'update' => "revert all {$entity_type_id} revisions", 'delete' => "delete all {$entity_type_id} revisions"];
     $bundle = $entity->bundle();
     $type_map = ['view' => "view {$entity_type_id} {$bundle} revisions", 'update' => "revert {$entity_type_id} {$bundle} revisions", 'delete' => "delete {$entity_type_id} {$bundle} revisions"];
     if (!$entity || !isset($map[$operation]) || !isset($type_map[$operation])) {
         // If there was no node to check against, or the $op was not one of the
         // supported ones, we return access denied.
         return FALSE;
     }
     // Statically cache access by revision ID, language code, user account ID,
     // and operation.
     $langcode = $entity->language()->getId();
     $cid = $entity->getRevisionId() . ':' . $langcode . ':' . $account->id() . ':' . $operation;
     if (!isset($this->accessCache[$cid])) {
         // Perform basic permission checks first.
         if (!$account->hasPermission($map[$operation]) && !$account->hasPermission($type_map[$operation]) && !$account->hasPermission('administer nodes')) {
             $this->accessCache[$cid] = FALSE;
             return FALSE;
         }
         if (($admin_permission = $entity_type->getAdminPermission()) && $account->hasPermission($admin_permission)) {
             $this->accessCache[$cid] = TRUE;
         } else {
             // First check the access to the default revision and finally, if the
             // node passed in is not the default revision then access to that, too.
             $this->accessCache[$cid] = $entity_access->access($entity_storage->load($entity->id()), $operation, $account) && ($entity->isDefaultRevision() || $entity_access->access($entity, $operation, $account));
         }
     }
     return $this->accessCache[$cid];
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:35,代码来源:EntityRevisionRouteAccessChecker.php

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

示例6: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = [];
     if ($items->status == 1 && $this->currentUser->hasPermission('view disqus comments')) {
         $element[] = ['#type' => 'disqus', '#url' => $items->getEntity()->toUrl('canonical', ['absolute' => TRUE])->toString(), '#title' => (string) $items->getEntity()->label(), '#identifier' => $items->identifier ?: "{$items->getEntity()->getEntityTypeId()}/{$items->getEntity()->id()}"];
     }
     return $element;
 }
开发者ID:MGApcDev,项目名称:MGApcDevCom,代码行数:11,代码来源:DisqusFormatter.php

示例7: onBlockPageDisplayVariantSelected

 /**
  * Selects the block place override of the block page display variant.
  *
  * @param \Drupal\Core\Render\PageDisplayVariantSelectionEvent $event
  *   The event to process.
  */
 public function onBlockPageDisplayVariantSelected(PageDisplayVariantSelectionEvent $event)
 {
     if ($event->getPluginId() === 'block_page') {
         if ($this->requestStack->getCurrentRequest()->query->has('block-place') && $this->account->hasPermission('administer blocks')) {
             $event->setPluginId('block_place_page');
         }
         $event->addCacheContexts(['user.permissions', 'url.query_args']);
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:15,代码来源:BlockPlaceEventSubscriber.php

示例8: isApplicable

 /**
  * {@inheritdoc}
  */
 public function isApplicable()
 {
     // Remove on Admin routes.
     $is_admin_route = $this->adminContext->isAdminRoute();
     // Remove on Block Demo page.
     $is_admin_demo_route = $this->routeMatch->getRouteName() === 'block.admin_demo';
     // @todo Check if there is actually a different admin theme.
     //   https://www.drupal.org/node/2784853
     return $this->account->hasPermission('administer blocks') && !$is_admin_route && !$is_admin_demo_route;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:OutsideInManager.php

示例9: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     if ($operation == 'view' || $operation == 'update') {
         if ($account->hasPermission('administer tmgmt') || $account->hasPermission('administer translation tasks')) {
             // Administrators can do everything.
             return AccessResult::allowed()->cachePerPermissions();
         }
         return AccessResult::allowedIf($entity->getTask()->tuid->target_id == $account->id() && $account->hasPermission('provide translation services'));
     }
     return $entity->getTask()->access($operation, $account, TRUE);
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:14,代码来源:LocalTaskItemAccessController.php

示例10: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     switch ($operation) {
         case 'view':
             // Check for status and set 'published' or 'unpublished'.
             $status = $entity->status->value ? 'published' : 'unpublished';
             return AccessResult::allowedIf($account->hasPermission('access content') && $account->hasPermission('view ' . $status . ' terms in ' . $entity->bundle()));
         default:
             return parent::checkAccess($entity, $operation, $account);
     }
 }
开发者ID:BurdaMagazinOrg,项目名称:thunder-distribution,代码行数:14,代码来源:ThunderTermAccessControlHandler.php

示例11: checkCreateAccess

 /**
  * {@inheritdoc}
  */
 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL)
 {
     if ($account->hasPermission('administer shortcuts')) {
         return TRUE;
     }
     if (!$account->hasPermission('access shortcuts')) {
         return FALSE;
     }
     if ($account->hasPermission('customize shortcut links')) {
         return TRUE;
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:15,代码来源:ShortcutSetAccessController.php

示例12: onRequest

 /**
  * Initializes devel module requirements.
  */
 public function onRequest(GetResponseEvent $event)
 {
     if (!devel_silent()) {
         if ($this->account->hasPermission('access devel information')) {
             devel_set_handler(devel_get_handlers());
             // We want to include the class early so that anyone may call krumo()
             // as needed. See http://krumo.sourceforge.net/
             has_krumo();
             // See http://www.firephp.org/HQ/Install.htm
             $path = NULL;
             if (@(include_once 'fb.php') || @(include_once 'FirePHPCore/fb.php')) {
                 // FirePHPCore is in include_path. Probably a PEAR installation.
                 $path = '';
             } elseif ($this->moduleHandler->moduleExists('libraries')) {
                 // Support Libraries API - http://drupal.org/project/libraries
                 $firephp_path = libraries_get_path('FirePHPCore');
                 $firephp_path = $firephp_path ? $firephp_path . '/lib/FirePHPCore/' : '';
                 $chromephp_path = libraries_get_path('chromephp');
             } else {
                 $firephp_path = DRUPAL_ROOT . '/libraries/FirePHPCore/lib/FirePHPCore/';
                 $chromephp_path = './' . drupal_get_path('module', 'devel') . '/chromephp';
             }
             // Include FirePHP if it exists.
             if (!empty($firephp_path) && file_exists($firephp_path . 'fb.php')) {
                 include_once $firephp_path . 'fb.php';
                 include_once $firephp_path . 'FirePHP.class.php';
             }
             // Include ChromePHP if it exists.
             if (!empty($chromephp_path) && file_exists($chromephp_path .= '/ChromePhp.php')) {
                 include_once $chromephp_path;
             }
         }
     }
     if ($this->config->get('rebuild_theme')) {
         drupal_theme_rebuild();
         // Ensure that the active theme object is cleared.
         $theme_name = \Drupal::theme()->getActiveTheme()->getName();
         \Drupal::state()->delete('theme.active_theme.' . $theme_name);
         \Drupal::theme()->resetActiveTheme();
         /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler*/
         $theme_handler = \Drupal::service('theme_handler');
         $theme_handler->refreshInfo();
         // @todo This is not needed after https://www.drupal.org/node/2330755
         $list = $theme_handler->listInfo();
         $theme_handler->addTheme($list[$theme_name]);
         if (\Drupal::service('flood')->isAllowed('devel.rebuild_theme_warning', 1)) {
             \Drupal::service('flood')->register('devel.rebuild_theme_warning');
             if (!devel_silent() && $this->account->hasPermission('access devel information')) {
                 drupal_set_message(t('The theme information is being rebuilt on every request. Remember to <a href=":url">turn off</a> this feature on production websites.', array(':url' => $this->urlGenerator->generateFromRoute('devel.admin_settings'))));
             }
         }
     }
 }
开发者ID:ABaldwinHunter,项目名称:durhamatletico-cms,代码行数:56,代码来源:DevelEventSubscriber.php

示例13: checkAccess

 /**
  * {@inheritdoc}
  */
 public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     if ($operation == 'view') {
         // Do not allow access personal category via site-wide route.
         return $account->hasPermission('access site-wide contact form') && $entity->id() !== 'personal';
     } elseif ($operation == 'delete' || $operation == 'update') {
         // Do not allow the 'personal' category to be deleted, as it's used for
         // the personal contact form.
         return $account->hasPermission('administer contact forms') && $entity->id() !== 'personal';
     }
     return parent::checkAccess($entity, $operation, $langcode, $account);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:15,代码来源:CategoryAccessController.php

示例14: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     switch ($operation) {
         case 'update':
             return AccessResult::allowedIf($account->hasPermission('administer grade letters'))->cachePerPermissions()->cacheUntilEntityChanges($entity);
         case 'delete':
             return AccessResult::allowedIf($account->hasPermission('administer grade letters') && $entity->getGradeLetterSet() != 'default')->cachePerPermissions();
         default:
             // No opinion.
             return AccessResult::neutral();
     }
 }
开发者ID:dakala,项目名称:gradebook,代码行数:15,代码来源:GradeLetterAccessControlHandler.php

示例15: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $element['status'] = ['#type' => 'checkbox', '#title' => t('Disqus Comments'), '#description' => t('Users can post comments using <a href=":disqus">Disqus</a>.', [':disqus' => 'http://disqus.com']), '#default_value' => isset($items->status) ? $items->status : TRUE, '#access' => $this->currentUser->hasPermission('toggle disqus comments')];
     $element['identifier'] = ['#type' => 'textfield', '#title' => $this->t('Disqus identifier'), '#description' => $this->t('Unique identifier of the Disqus thread. "[entity-type]/[entity-id]" is used if not set. Changing this might cause comments to disappear. Use extreme caution!'), '#default_value' => isset($items->identifier) ? $items->identifier : '', '#access' => $this->currentUser->hasPermission('administer disqus')];
     // If the advanced settings tabs-set is available (normally rendered in the
     // second column on wide-resolutions), place the field as a details element
     // in this tab-set.
     if (isset($form['advanced'])) {
         $element += array('#type' => 'details', '#group' => 'advanced');
     }
     return $element;
 }
开发者ID:hugronaphor,项目名称:cornel,代码行数:15,代码来源:DisqusWidget.php


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