當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityInterface::access方法代碼示例

本文整理匯總了PHP中Drupal\Core\Entity\EntityInterface::access方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityInterface::access方法的具體用法?PHP EntityInterface::access怎麽用?PHP EntityInterface::access使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Entity\EntityInterface的用法示例。


在下文中一共展示了EntityInterface::access方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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) {
   if ($profile->access('view')) {
     $this->options['alter']['make_link'] = TRUE;
     $this->options['alter']['path'] = 'profile/' . $profile->id();
     return $profile->label();
   }
 }
開發者ID:housineali,項目名稱:drpl8_dv,代碼行數:18,代碼來源:Label.php

示例2: renderLink

 /**
  * Prepares the link to the node.
  *
  * @param \Drupal\Core\Entity\EntityInterface $node
  *   The node 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($node, ResultRow $values)
 {
     if ($node->access('view')) {
         $this->options['alter']['make_link'] = TRUE;
         $this->options['alter']['path'] = 'node/' . $node->id();
         $text = !empty($this->options['text']) ? $this->options['text'] : t('View');
         return $text;
     }
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:20,代碼來源:Link.php

示例3: renderLink

 /**
  * Prepares the link to the node.
  *
  * @param \Drupal\Core\Entity\EntityInterface $node
  *   The node 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($node, ResultRow $values)
 {
     if ($node->access('view')) {
         $this->options['alter']['make_link'] = TRUE;
         $this->options['alter']['url'] = $node->urlInfo();
         $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('View');
         return $text;
     }
 }
開發者ID:dev981,項目名稱:gaptest,代碼行數:20,代碼來源:Link.php

示例4: renderLink

 /**
  * {@inheritdoc}
  */
 protected function renderLink(EntityInterface $entity, ResultRow $values)
 {
     if ($entity && $entity->access('update')) {
         $this->options['alter']['make_link'] = TRUE;
         $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit');
         $this->options['alter']['url'] = $entity->urlInfo('edit-form', ['query' => ['destination' => $this->getDestinationArray()]]);
         return $text;
     }
 }
開發者ID:dev981,項目名稱:gaptest,代碼行數:12,代碼來源:LinkEdit.php

示例5: accessReport

 /**
  * Determines if the user specified has access to report the entity.
  *
  * @param \Drupal\core\Entity\EntityInterface $entity
  *   The entity to check access for
  * @param $form_id string
  *   The form that is protected for this entity.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The account to use.  If null, use the current user.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  */
 public static function accessReport($entity, $form_id, $account = NULL)
 {
     // Check if the user has access to this comment.
     $result = $entity->access('edit', $account, TRUE)->andIf($entity->access('update', $account, TRUE));
     if (!$result->isAllowed()) {
         return $result;
     }
     // Check if this entity type is protected.
     $form_entity = \Drupal::entityManager()->getStorage('mollom_form')->load($form_id);
     if (empty($form_entity)) {
         return new AccessResultForbidden();
     }
     // Check any specific report access callbacks.
     $forms = FormController::getProtectableForms();
     $info = $forms[$form_id];
     if (empty($info)) {
         // Orphan form protection.
         return new AccessResultForbidden();
     }
     $report_access_callbacks = [];
     $access_permissions = [];
     // If there is a 'report access callback' add it to the list.
     if (isset($info['report access callback']) && function_exists($info['report access callback']) && !in_array($info['report access callback'], $report_access_callbacks)) {
         $report_access_callbacks[] = $info['report access callback'];
     } else {
         if (isset($info['report access']) && !in_array($info['report access'], $access_permissions)) {
             $access_permissions += $info['report access'];
         }
     }
     foreach ($report_access_callbacks as $callback) {
         if (!$callback($entity->getEntityTypeId(), $entity->id())) {
             return new AccessResultForbidden();
         }
     }
     foreach ($access_permissions as $permission) {
         if (empty($account)) {
             $account = \Drupal::currentUser();
         }
         if (!$account->hasPermission($permission)) {
             return new AccessResultForbidden();
         }
     }
     return new AccessResultAllowed();
 }
開發者ID:isramv,項目名稱:camp-gdl,代碼行數:56,代碼來源:EntityReportAccessManager.php

示例6: renderLink

 /**
  * {@inheritdoc}
  */
 protected function renderLink(EntityInterface $entity, ResultRow $values)
 {
     if ($entity && $entity->access('delete')) {
         $this->options['alter']['make_link'] = TRUE;
         $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Cancel account');
         $this->options['alter']['url'] = $entity->urlInfo('cancel-form');
         $this->options['alter']['query'] = drupal_get_destination();
         return $text;
     }
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:13,代碼來源:LinkCancel.php

示例7: access

 /**
  * {@inheritdoc}
  */
 protected function access()
 {
     // Drupal 8 has unified APIs for access checks so this is pretty easy.
     if (is_object($this->entity)) {
         $entity_access = $this->entity->access('view');
         $field_access = $this->entity->{$this->fieldName}->access('view');
         return $entity_access && $field_access;
     }
     return FALSE;
 }
開發者ID:pulibrary,項目名稱:recap,代碼行數:13,代碼來源:JuiceboxXmlControllerField.php

示例8: testAccess

 /**
  * Assert unaccessible items don't change the data of the fields.
  */
 public function testAccess()
 {
     $field_name = $this->fieldName;
     $referencing_entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
     $referencing_entity->save();
     $referencing_entity->{$field_name}->entity = $this->referencedEntity;
     // Assert user doesn't have access to the entity.
     $this->assertFalse($this->referencedEntity->access('view'), 'Current user does not have access to view the referenced entity.');
     $formatter_manager = $this->container->get('plugin.manager.field.formatter');
     // Get all the existing formatters.
     foreach ($formatter_manager->getOptions('entity_reference') as $formatter => $name) {
         // Set formatter type for the 'full' view mode.
         entity_get_display($this->entityType, $this->bundle, 'default')->setComponent($field_name, array('type' => $formatter))->save();
         // Invoke entity view.
         entity_view($referencing_entity, 'default');
         // Verify the un-accessible item still exists.
         $this->assertEqual($referencing_entity->{$field_name}->target_id, $this->referencedEntity->id(), format_string('The un-accessible item still exists after @name formatter was executed.', array('@name' => $name)));
     }
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:22,代碼來源:EntityReferenceFormatterTest.php

示例9: renderLink

 /**
  * {@inheritdoc}
  */
 protected function renderLink(EntityInterface $entity, ResultRow $values)
 {
     if ($entity && $entity->access('update')) {
         $this->options['alter']['make_link'] = TRUE;
         $text = !empty($this->options['text']) ? $this->options['text'] : t('Edit');
         $this->options['alter']['path'] = $entity->getSystemPath('edit-form');
         $this->options['alter']['query'] = drupal_get_destination();
         return $text;
     }
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:13,代碼來源:LinkEdit.php

示例10: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity)
 {
     // Only check access if the current file access control handler explicitly
     // opts in by implementing FileAccessFormatterControlHandlerInterface.
     $access_handler_class = $entity->getEntityType()->getHandlerClass('access');
     if (is_subclass_of($access_handler_class, '\\Drupal\\file\\FileAccessFormatterControlHandlerInterface')) {
         return $entity->access('view', NULL, TRUE);
     } else {
         return AccessResult::allowed();
     }
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:14,代碼來源:FileFormatterBase.php

示例11: renderLink

  /**
   * Prepares the link to delete a profile.
   *
   * @param \Drupal\Core\Entity\EntityInterface $profile
   *   The profile entity this field belongs to.
   * @param \Drupal\views\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 delete this node.
    if (!$profile->access('delete')) {
      return;
    }

    $this->options['alter']['make_link'] = TRUE;
    $this->options['alter']['path'] = 'profile/' . $profile->id() . '/delete';
    $this->options['alter']['query'] = \Drupal::destination()->getAsArray();
    $text = !empty($this->options['text']) ? $this->options['text'] : t('Delete');
    return $text;
  }
開發者ID:housineali,項目名稱:drpl8_dv,代碼行數:23,代碼來源:LinkDelete.php

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

示例13: renderLink

 /**
  * Prepares the link to the node.
  *
  * @param \Drupal\Core\Entity\EntityInterface $node
  *   The node 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($node, ResultRow $values)
 {
     // Ensure user has access to edit this node.
     if (!$node->access('update')) {
         return;
     }
     $this->options['alter']['make_link'] = TRUE;
     $this->options['alter']['url'] = $node->urlInfo('edit-form');
     $this->options['alter']['query'] = $this->getDestinationArray();
     $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit');
     return $text;
 }
開發者ID:dev981,項目名稱:gaptest,代碼行數:23,代碼來源:LinkEdit.php

示例14: renderLink

 /**
  * Prepares the link to the node.
  *
  * @param \Drupal\Core\Entity\EntityInterface $node
  *   The node 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($node, ResultRow $values)
 {
     // Ensure user has access to edit this node.
     if (!$node->access('update')) {
         return;
     }
     $this->options['alter']['make_link'] = TRUE;
     $this->options['alter']['path'] = "node/" . $node->id() . "/edit";
     $this->options['alter']['query'] = drupal_get_destination();
     $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit');
     return $text;
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:23,代碼來源:LinkEdit.php

示例15: renderLink

 /**
  * Prepares the link to delete a node.
  *
  * @param \Drupal\Core\Entity\EntityInterface $node
  *   The node entity this field belongs to.
  * @param \Drupal\views\ResultRow $values
  *   The values retrieved from the view's result set.
  *
  * @return string
  *   Returns a string for the link text.
  */
 protected function renderLink($node, ResultRow $values)
 {
     // Ensure user has access to delete this node.
     if (!$node->access('delete')) {
         return;
     }
     $this->options['alter']['make_link'] = TRUE;
     $this->options['alter']['path'] = $node->getSystemPath('delete-form');
     $this->options['alter']['query'] = drupal_get_destination();
     $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Delete');
     return $text;
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:23,代碼來源:LinkDelete.php


注:本文中的Drupal\Core\Entity\EntityInterface::access方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。