summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/file/src/FileAccessControlHandler.php
diff options
context:
space:
mode:
authorAlex Pott <alex.a.pott@googlemail.com>2014-08-07 23:27:28 +0100
committerAlex Pott <alex.a.pott@googlemail.com>2014-08-07 23:27:28 +0100
commit258856aee9940b0d59077d62eb7a3c8f155dd7f4 (patch)
treeec5dbdfa0e0f40c6ec2b9290ea72a6c3635591e1 /core/modules/file/src/FileAccessControlHandler.php
parenta04820c1da4c778fc481bd64967451be205e1b1f (diff)
downloaddrupal-258856aee9940b0d59077d62eb7a3c8f155dd7f4.tar.gz
drupal-258856aee9940b0d59077d62eb7a3c8f155dd7f4.zip
Issue #2154435 by andypost, Berdir, mparker17: Rename EntityAccessController to EntityAccessControlHandler.
Diffstat (limited to 'core/modules/file/src/FileAccessControlHandler.php')
-rw-r--r--core/modules/file/src/FileAccessControlHandler.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/core/modules/file/src/FileAccessControlHandler.php b/core/modules/file/src/FileAccessControlHandler.php
new file mode 100644
index 000000000000..ee62c2277e42
--- /dev/null
+++ b/core/modules/file/src/FileAccessControlHandler.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\file\FileAccessControlHandler.
+ */
+
+namespace Drupal\file;
+
+use Drupal\Core\Entity\EntityAccessControlHandler;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Provides a File access control handler.
+ */
+class FileAccessControlHandler extends EntityAccessControlHandler {
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
+
+ if ($operation == 'download') {
+ foreach ($this->getFileReferences($entity) as $field_name => $entity_map) {
+ foreach ($entity_map as $referencing_entity_type => $referencing_entities) {
+ /** @var \Drupal\Core\Entity\EntityInterface $referencing_entity */
+ foreach ($referencing_entities as $referencing_entity) {
+ if ($referencing_entity->access('view', $account) && $referencing_entity->$field_name->access('view', $account)) {
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+ }
+ }
+
+ /**
+ * Wrapper for file_get_file_references().
+ *
+ * @param \Drupal\file\FileInterface $file
+ * The file object for which to get references.
+ *
+ * @return array
+ * A multidimensional array. The keys are field_name, entity_type,
+ * entity_id and the value is an entity referencing this file.
+ *
+ * @see file_get_file_references()
+ */
+ protected function getFileReferences(FileInterface $file) {
+ return file_get_file_references($file, NULL, EntityStorageInterface::FIELD_LOAD_REVISION, NULL);
+ }
+
+}