Issue #2692091 by amateescu, heykarthikwithu, xjm, Berdir: Use the new 'view label' entity access check in the entity reference label formatter

8.4.x
Nathaniel Catchpole 2017-02-13 17:40:45 +00:00
parent e05ae29399
commit a6a513dff9
5 changed files with 12 additions and 6 deletions

View File

@ -169,9 +169,9 @@ abstract class EntityReferenceFormatterBase extends FormatterBase {
/**
* Checks access to the given entity.
*
* By default, entity access is checked. However, a subclass can choose to
* exclude certain items from entity access checking by immediately granting
* access.
* By default, entity 'view' access is checked. However, a subclass can choose
* to exclude certain items from entity access checking by immediately
* granting access.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to check.

View File

@ -2,6 +2,7 @@
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
@ -100,4 +101,11 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {
return $elements;
}
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity) {
return $entity->access('view label', NULL, TRUE);
}
}

View File

@ -54,9 +54,7 @@ class AuthorFormatter extends EntityReferenceFormatterBase {
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity) {
// Always allow an entity author's username to be read, even if the current
// user does not have permission to view the entity author's profile.
return AccessResult::allowed();
return $entity->access('view label', NULL, TRUE);
}
}