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


PHP EntityInterface::getOwnerId方法代码示例

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


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

示例1: checkAccess

 /**
  * {@inheritdoc}
  *
  * When the $operation is 'add' then the $entity is of type 'profile_type',
  * otherwise $entity is of type 'profile'.
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     $account = $this->prepareUser($account);
     $user_page = \Drupal::request()->attributes->get('user');
     // Some times, operation edit is called update.
     // Use edit in any case.
     if ($operation == 'update') {
         $operation = 'edit';
     }
     // Check that if profile type has require roles, the user the profile is
     // being added to has any of the required roles.
     if ($entity->getEntityTypeId() == 'profile') {
         $profile_roles = ProfileType::load($entity->bundle())->getRoles();
         $user_roles = $entity->getOwner()->getRoles(TRUE);
         if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
             return AccessResult::forbidden();
         }
     } elseif ($entity->getEntityTypeId() == 'profile_type') {
         $profile_roles = $entity->getRoles();
         $user_roles = User::load($user_page->id())->getRoles(TRUE);
         if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
             return AccessResult::forbidden();
         }
     }
     if ($account->hasPermission('bypass profile access')) {
         return AccessResult::allowed()->cachePerPermissions();
     } elseif ($operation == 'add' && ($user_page->id() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->id() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->id() . ' profile')) || $operation != 'add' && ($entity->getOwnerId() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->getType() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->getType() . ' profile'))) {
         return AccessResult::allowed()->cachePerPermissions();
     } else {
         return AccessResult::forbidden()->cachePerPermissions();
     }
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:38,代码来源:ProfileAccessControlHandler.php

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

示例3: renderLink

  /**
   * Prepares the link to the profile.
   *
   * @param \Drupal\Core\Entity\EntityInterface $profile
   *   The profile entity this field belongs to.
   * @param ResultRow $values
   *   The values retrieved from the view's result set.
   *
   * @return string
   *   Returns a string for the link text.
   */
  protected function renderLink($profile, ResultRow $values) {
    // Ensure user has access to edit this profile.
    if (!$profile->access('update')) {
      return;
    }

    $this->options['alter']['make_link'] = TRUE;
    $this->options['alter']['path'] = "user/" . $profile->getOwnerId() . "/profile/" . $profile->bundle() . "/" . $profile->id();
    $this->options['alter']['query'] = \Drupal::destination()->getAsArray();
    $text = !empty($this->options['text']) ? $this->options['text'] : t('Edit');
    return $text;
  }
开发者ID:housineali,项目名称:drpl8_dv,代码行数:23,代码来源:LinkEdit.php

示例4: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     /** @var ScheduledUpdate $entity */
     if ($operation == 'view') {
         return AccessResult::allowedIfHasPermission($account, 'view scheduled update entities');
     }
     $type_id = $entity->bundle();
     if ($entity->getOwnerId() == $account->id()) {
         // If owner that needs either own or any permission, not both.
         return AccessResult::allowedIfHasPermissions($account, ["{$operation} any {$type_id} scheduled updates", "{$operation} own {$type_id} scheduled updates"], 'OR');
     } else {
         return AccessResult::allowedIfHasPermission($account, "{$operation} any {$type_id} scheduled updates");
     }
 }
开发者ID:tedbow,项目名称:scheduled-updates-demo,代码行数:17,代码来源:ScheduledUpdateAccessControlHandler.php

示例5: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $support_ticket, $operation, AccountInterface $account)
 {
     /** @var \Drupal\support_ticket\SupportTicketInterface $support_ticket */
     // Fetch information from the support_ticket object if possible.
     $status = $support_ticket->isPublished();
     $uid = $support_ticket->getOwnerId();
     // Check if authors can view their own unpublished support tickets.
     if ($operation === 'view' && !$status && $account->hasPermission('view own unpublished support tickets') && $account->isAuthenticated() && $account->id() == $uid) {
         return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($support_ticket);
     }
     if ($operation === 'view') {
         return AccessResult::allowedIf($status)->cacheUntilEntityChanges($support_ticket);
     }
     // No opinion.
     return AccessResult::neutral();
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:19,代码来源:SupportTicketAccessControlHandler.php

示例6: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     $account = $this->prepareUser($account);
     $user_page = \Drupal::request()->attributes->get('user');
     // Some times, operation edit is called update.
     // Use edit in any case.
     if ($operation == 'update') {
         $operation = 'edit';
     }
     if ($account->hasPermission('bypass profile access')) {
         return AccessResult::allowed()->cachePerPermissions();
     } elseif ($operation == 'add' && ($user_page->id() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->id() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->id() . ' profile')) || $operation != 'add' && ($entity->getOwnerId() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->getType() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->getType() . ' profile'))) {
         return AccessResult::allowed()->cachePerPermissions();
     } else {
         return AccessResult::forbidden()->cachePerPermissions();
     }
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:20,代码来源:ProfileAccessControlHandler.php

示例7: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\user\EntityOwnerInterface $entity */
     switch ($operation) {
         case 'view':
             return $account->hasPermission('access comments');
             break;
         case 'update':
             return $account->id() && $account->id() == $entity->getOwnerId() && $entity->status->value == CommentInterface::PUBLISHED && $account->hasPermission('edit own comments') || $account->hasPermission('administer comments');
             break;
         case 'delete':
             return $account->hasPermission('administer comments');
             break;
         case 'approve':
             return $account->hasPermission('administer comments');
             break;
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:21,代码来源:CommentAccessController.php

示例8: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $order, $operation, AccountInterface $account)
 {
     /** @var \Drupal\uc_order\OrderInterface $order */
     switch ($operation) {
         case 'view':
         case 'invoice':
             // Admins can view all orders.
             if ($account->hasPermission('view all orders')) {
                 return AccessResult::allowed()->cachePerPermissions();
             }
             // Non-anonymous users can view their own orders and invoices with permission.
             $permission = $operation == 'view' ? 'view own orders' : 'view own invoices';
             if ($account->id() && $account->id() == $order->getOwnerId() && $account->hasPermission($permission)) {
                 return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($order);
             }
             return AccessResult::forbidden()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($order);
         case 'update':
             return AccessResult::allowedIfHasPermission($account, 'edit orders')->cachePerPermissions()->cachePerUser();
         case 'delete':
             if ($account->hasPermission('unconditionally delete orders')) {
                 // Unconditional deletion perms are always TRUE.
                 return AccessResult::allowed()->cachePerPermissions()->cachePerUser();
             }
             if ($account->hasPermission('delete orders')) {
                 // Only users with unconditional deletion perms can delete completed orders.
                 if ($order->getStateId() == 'completed') {
                     return AccessResult::forbidden()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($order);
                 } else {
                     // See if any modules have a say in this order's eligibility for deletion.
                     $module_handler = \Drupal::moduleHandler();
                     foreach ($module_handler->getImplementations('uc_order_can_delete') as $module) {
                         $function = $module . '_uc_order_can_delete';
                         if ($function($order) === FALSE) {
                             return AccessResult::forbidden()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($order);
                         }
                     }
                     return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($order);
                 }
             }
             return AccessResult::forbidden()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($order);
     }
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:45,代码来源:OrderAccessControlHandler.php

示例9: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\user\EntityOwnerInterface $entity */
     switch ($operation) {
         case 'view':
             if ($account->hasPermission('access comments') && $entity->isPublished() || $account->hasPermission('administer comments')) {
                 return $entity->getCommentedEntity()->access($operation, $account);
             }
             break;
         case 'update':
             return $account->id() && $account->id() == $entity->getOwnerId() && $entity->isPublished() && $account->hasPermission('edit own comments') || $account->hasPermission('administer comments');
             break;
         case 'delete':
             return $account->hasPermission('administer comments');
             break;
         case 'approve':
             return $account->hasPermission('administer comments');
             break;
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:23,代码来源:CommentAccessController.php

示例10: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     switch ($operation) {
         case 'view':
             if ($account->hasPermission('access grade items') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId()) {
                 return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($entity);
             }
         case 'update':
             if ($account->hasPermission('administer grade items')) {
                 return AccessResult::allowed()->cachePerPermissions();
             }
             if (!$account->hasPermission('access grade items')) {
                 return AccessResult::neutral()->cachePerPermissions();
             }
             return AccessResult::allowedIf($account->hasPermission('customize grade items') && $entity == grade_scale_current_displayed_set($account))->cachePerPermissions()->cacheUntilEntityChanges($entity);
         case 'delete':
             return AccessResult::allowedIf($account->hasPermission('administer grade items') && $entity->id() != 'default')->cachePerPermissions();
         default:
             // No opinion.
             return AccessResult::neutral();
     }
 }
开发者ID:dakala,项目名称:gradebook,代码行数:25,代码来源:GradeItemAccessControlHandler.php

示例11: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $node, $operation, AccountInterface $account)
 {
     /** @var \Drupal\node\NodeInterface $node */
     // Fetch information from the node object if possible.
     $status = $node->isPublished();
     $uid = $node->getOwnerId();
     // Check if authors can view their own unpublished nodes.
     if ($operation === 'view' && !$status && $account->hasPermission('view own unpublished content') && $account->isAuthenticated() && $account->id() == $uid) {
         return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($node);
     }
     // Evaluate node grants.
     return $this->grantStorage->access($node, $operation, $account);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:16,代码来源:NodeAccessControlHandler.php

示例12: getAdditionalCacheTagsForEntity

 /**
  * {@inheritdoc}
  *
  * Each comment must have a comment body, which always has a text format.
  */
 protected function getAdditionalCacheTagsForEntity(EntityInterface $entity)
 {
     /** @var \Drupal\comment\CommentInterface $entity */
     return array('filter_format:plain_text', 'user:' . $entity->getOwnerId(), 'user_view');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:CommentCacheTagsTest.php

示例13: getAdditionalCacheTagsForEntity

 /**
  * {@inheritdoc}
  *
  * Each node must have an author.
  */
 protected function getAdditionalCacheTagsForEntity(EntityInterface $node)
 {
     return array('user:' . $node->getOwnerId(), 'user_view');
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:9,代码来源:NodeCacheTagsTest.php

示例14: buildRow

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    /** @var \Drupal\profile\ProfileInterface $entity */
    $mark = [
      '#theme' => 'mark',
      '#mark_type' => node_mark($entity->id(), $entity->getChangedTime()),
    ];
    $langcode = $entity->language()->id;
    $uri = $entity->urlInfo();
    $options = $uri->getOptions();
    $options += ($langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? ['language' => $languages[$langcode]] : []);
    $uri->setOptions($options);
    $row['label']['data'] = [
        '#type' => 'link',
        '#title' => $entity->label(),
        '#suffix' => ' ' . drupal_render($mark),
      ] + $uri->toRenderArray();
    $row['type'] = $entity->getType()->id();
    $row['owner']['data'] = [
      '#theme' => 'username',
      '#account' => $entity->getOwner(),
    ];
    $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
    $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
    $language_manager = \Drupal::languageManager();
    if ($language_manager->isMultilingual()) {
      $row['language_name'] = $language_manager->getLanguageName($langcode);
    }

    $route_params = ['user' => $entity->getOwnerId(), 'type' => $entity->bundle(), 'profile' => $entity->id()];
    $links['edit'] = [
      'title' => t('Edit'),
      'route_name' => 'entity.profile.edit_form',
      'route_parameters' => $route_params,
    ];
    $links['delete'] = [
      'title' => t('Delete'),
      'route_name' => 'entity.profile.delete_form',
      'route_parameters' => $route_params,
    ];

    $row[] = [
      'data' => [
        '#type' => 'operations',
        '#links' => $links,
      ],
    ];

    return $row + parent::buildRow($entity);
  }
开发者ID:housineali,项目名称:drpl8_dv,代码行数:52,代码来源:ProfileListBuilder.php

示例15: assignPlayerToTeam

 /**
  * Assign a player to a team.
  *
  * Incoming entity will be a registration node with a reference
  * to a team. When that's updated, load the team node and make
  * sure the player is assigned/removed from the team node.
  *
  * TODO: This does not update the previous revision, so manual
  * clean up is needed if the player is switched to a different
  * team.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  */
 public function assignPlayerToTeam(\Drupal\Core\Entity\EntityInterface $entity)
 {
     $team_nid = $entity->get('field_registration_teams')->getValue();
     if (isset($team_nid[0]['target_id'])) {
         $team_node = \Drupal\node\Entity\Node::load($team_nid[0]['target_id']);
         $player_nids = array_merge($team_node->get('field_players')->getValue(), array(array('target_id' => $entity->getOwnerId())));
         $player_nids = array_map("unserialize", array_unique(array_map("serialize", $player_nids)));
         $team_node->get('field_players')->setValue($player_nids);
         $team_node->save();
     }
 }
开发者ID:ABaldwinHunter,项目名称:durhamatletico-cms,代码行数:24,代码来源:RegistrationService.php


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