本文整理汇总了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();
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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();
}
示例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;
}
}
示例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;
}
示例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)));
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}