diff --git a/core/modules/comment/src/CommentAccessControlHandler.php b/core/modules/comment/src/CommentAccessControlHandler.php index 158c48b..e8a214c 100644 --- a/core/modules/comment/src/CommentAccessControlHandler.php +++ b/core/modules/comment/src/CommentAccessControlHandler.php @@ -115,7 +115,7 @@ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_ // mail field is hidden from non-admins. $admin_access = AccessResult::allowedIf($account->hasPermission('administer comments') && $field_definition->getName() != 'hostname') ->cachePerRole(); - $anonymous_access = AccessResult::allowedIf($account->hasPermission('access comments') && $entity && $entity->isPublished() && !in_array($field_definition->getName(), array('mail', 'hostname'), TRUE)) + $anonymous_access = AccessResult::allowedIf($account->hasPermission('access comments') && (!$entity || $entity->isPublished()) && !in_array($field_definition->getName(), array('mail', 'hostname'), TRUE)) ->cachePerRole(); if ($entity) { $anonymous_access->cacheUntilEntityChanges($entity); diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index 3bee3ac..0ccb8e2 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -370,10 +370,7 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co } // Add access callbacks. $views_field['field']['access callback'] = 'views_entity_base_field_access'; - $views_field['field']['access arguments'] = [ - 'entity_type_id' => $this->entityType->id(), - 'field_name' => $field_definition->getName(), - ]; + $views_field['field']['field access'] = $this->entityType->id() . ':' . $field_definition->getName(); return $views_field; } diff --git a/core/modules/views/src/Plugin/views/field/Standard.php b/core/modules/views/src/Plugin/views/field/Standard.php index 11ecc6a..472667b 100644 --- a/core/modules/views/src/Plugin/views/field/Standard.php +++ b/core/modules/views/src/Plugin/views/field/Standard.php @@ -6,6 +6,9 @@ */ namespace Drupal\views\Plugin\views\field; +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Session\AccountInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Default implementation of the base field plugin. @@ -16,4 +19,49 @@ */ class Standard extends FieldPluginBase { + /** + * Entity manager service. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * {@inheritdoc} + */ + public function access(AccountInterface $account) { + if (isset($this->definition['field access']) && strstr($this->definition['field access'], ':') !== FALSE) { + list($entity_type_id, $field_name) = explode(':', $this->definition['field access']); + $access_handler = $this->entityManager->getAccessControlHandler($entity_type_id); + $field_definition = $this->entityManager->getBaseFieldDefinitions($entity_type_id)[$field_name]; + return $access_handler->fieldAccess('view', $field_definition, $account); + } + + return parent::access($account); + } + + /** + * Constructs a new Standard field handler. + * + * @param array $configuration + * The plugin configuration. + * @param string $plugin_id + * The plugin ID. + * @param mixed $plugin_definition + * The plugin definition. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * Entity manager service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager')); + } + } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 813d32e..bee8d1f 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -920,23 +920,3 @@ function views_local_tasks_alter(&$local_tasks) { $local_task = ViewsLocalTask::create($container, 'views_view'); $local_task->alterLocalTasks($local_tasks); } - -/** - * Provides access callback for entity base fields. - * - * @param \Drupal\Core\Session\AccountInterface $account - * The account to check access against. - * @param string $entity_type_id - * The entity type ID for the base field. - * @param string $field_name - * The base field name. - * - * @return bool - * TRUE if access is allowed. - */ -function views_entity_base_field_access(AccountInterface $account, $entity_type_id, $field_name) { - $entity_manager = \Drupal::entityManager(); - $access_handler = $entity_manager->getAccessControlHandler($entity_type_id); - $field_definition = $entity_manager->getBaseFieldDefinitions($entity_type_id)[$field_name]; - return $access_handler->fieldAccess('view', $field_definition, $account); -}