Security update for permissions_by_term
[yaffs-website] / vendor / drupal / drupal-driver / src / Drupal / Driver / Fields / Drupal7 / FileHandler.php
1 <?php
2
3 namespace Drupal\Driver\Fields\Drupal7;
4
5 /**
6  * File field handler for Drupal 7.
7  */
8 class FileHandler extends AbstractHandler {
9
10   /**
11    * {@inheritdoc}
12    *
13    * Specify files in file fields by their filename.
14    */
15   public function expand($values) {
16     $return = array();
17
18     foreach ($values as $value) {
19       $query = new \EntityFieldQuery();
20
21       $query->entityCondition('entity_type', 'file')
22         ->propertyCondition('filename', $value)
23         ->propertyOrderBy('timestamp', 'DESC')
24         ->range(0, 1);
25
26       $result = $query->execute();
27
28       if (!empty($result['file'])) {
29         $files = entity_load('file', array_keys($result['file']));
30         $file = current($files);
31
32         $return[$this->language][] = array(
33           'filename' => $file->filename,
34           'uri' => $file->uri,
35           'fid' => $file->fid,
36           'display' => 1,
37         );
38       }
39       else {
40         throw new \Exception(sprintf('File with filename "%s" not found.', $value));
41       }
42     }
43
44     return $return;
45   }
46
47 }