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.
|
* Checks access to the given entity.
|
||||||
*
|
*
|
||||||
* By default, entity access is checked. However, a subclass can choose to
|
* By default, entity 'view' access is checked. However, a subclass can choose
|
||||||
* exclude certain items from entity access checking by immediately granting
|
* to exclude certain items from entity access checking by immediately
|
||||||
* access.
|
* granting access.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||||
* The entity to check.
|
* The entity to check.
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
|
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
|
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
|
||||||
use Drupal\Core\Field\FieldItemListInterface;
|
use Drupal\Core\Field\FieldItemListInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
@ -100,4 +101,11 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {
|
||||||
return $elements;
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function checkAccess(EntityInterface $entity) {
|
protected function checkAccess(EntityInterface $entity) {
|
||||||
// Always allow an entity author's username to be read, even if the current
|
return $entity->access('view label', NULL, TRUE);
|
||||||
// user does not have permission to view the entity author's profile.
|
|
||||||
return AccessResult::allowed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue