forked from jhedstrom/DrupalDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileHandler.php
52 lines (41 loc) · 1.09 KB
/
FileHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @file
* Contains \Drupal\Driver\Fields\Drupal7\FileHandler.
*/
namespace Drupal\Driver\Fields\Drupal7;
/**
* File field handler for Drupal 7.
*/
class FileHandler extends AbstractHandler {
/**
* {@inheritdoc}
*
* Specify files in file fields by their filename.
*/
public function expand($values) {
$return = array();
foreach ($values as $value) {
$query = new \EntityFieldQuery();
$query->entityCondition('entity_type', 'file')
->propertyCondition('filename', $value)
->propertyOrderBy('timestamp', 'DESC')
->range(0, 1);
$result = $query->execute();
if (!empty($result['file'])) {
$files = entity_load('file', array_keys($result['file']));
$file = current($files);
$return[$this->language][] = array(
'filename' => $file->filename,
'uri' => $file->uri,
'fid' => $file->fid,
'display' => 1,
);
}
else {
throw new \Exception(sprintf('File with filename "%s" not found.', $value));
}
}
return $return;
}
}