Issue #2692091 by amateescu, heykarthikwithu, xjm, Berdir: Use the new 'view label' entity access check in the entity reference label formatter
parent
e05ae29399
commit
a6a513dff9
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue