diff --git a/modules/ctools_block/src/Plugin/Block/EntityField.php b/modules/ctools_block/src/Plugin/Block/EntityField.php index 6d4f292..a3b4209 100644 --- a/modules/ctools_block/src/Plugin/Block/EntityField.php +++ b/modules/ctools_block/src/Plugin/Block/EntityField.php @@ -8,7 +8,6 @@ namespace Drupal\ctools_block\Plugin\Block; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\EntityFieldManagerInterface; @@ -146,8 +145,11 @@ class EntityField extends BlockBase implements ContextAwarePluginInterface, Cont /** @var \Drupal\Core\Field\FieldItemListInterface $field */ $field = $entity->{$this->fieldName}; - $display_settings = $this->getConfiguration()['formatter']; - $build['field'] = $field->view($display_settings); + $access_handler = $this->entityTypeManager->getAccessControlHandler($this->entityTypeId); + if ($access_handler->access($entity, 'view') && $access_handler->fieldAccess('view', $this->getFieldDefinition(), NULL, $field)) { + $display_settings = $this->getConfiguration()['formatter']; + $build['field'] = $field->view($display_settings); + } } CacheableMetadata::createFromObject($entity) @@ -157,23 +159,11 @@ class EntityField extends BlockBase implements ContextAwarePluginInterface, Cont } /** - * {@inheritdoc} + * @inheritDoc */ protected function blockAccess(AccountInterface $account) { - /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */ - $entity = $this->getContextValue('entity'); - - if ($entity instanceof FieldableEntityInterface && $entity->hasField($this->fieldName)) { - /** @var \Drupal\Core\Field\FieldItemListInterface $field */ - $field = $entity->{$this->fieldName}; - - $access_handler = $this->entityTypeManager->getAccessControlHandler($this->entityTypeId); - if ($access_handler->access($entity, 'view') && $access_handler->fieldAccess('view', $this->getFieldDefinition(), $account, $field)) { - return AccessResult::allowed(); - } - } - - return AccessResult::forbidden(); + $access_handler = $this->entityTypeManager->getAccessControlHandler($this->entityTypeId); + return $access_handler->fieldAccess('view', $this->getFieldDefinition(), $account, NULL, TRUE); } /**