public function RealisticDummyContentAttribute::valueFromFiles in Realistic Dummy Content 7.2
Same name and namespace in other branches
- 8.2 api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::valueFromFiles()
- 3.x api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::valueFromFiles()
Given a list of files, return a value from one of them.
Parameters
array $files: An array of file objects.
Return value
mixed A file object or array, or an associative array with the keys "value" and "format", or NULL if there are no files to choose from or the files have the wrong extension.
1 call to RealisticDummyContentAttribute::valueFromFiles()
- RealisticDummyContentAttribute::changeFromFiles in api/
src/ includes/ RealisticDummyContentAttribute.php - Given candidate files, change value of this attribute based on one of them.
File
- api/
src/ includes/ RealisticDummyContentAttribute.php, line 242
Class
- RealisticDummyContentAttribute
- Represents either a field or a property for an entity.
Namespace
Drupal\realistic_dummy_content_api\includesCode
public function valueFromFiles($files) {
try {
if (count($files)) {
$rand_index = $this
->rand(0, count($files) - 1);
$file = $files[$rand_index];
return $this
->valueFromFile($file);
}
} catch (Exception $e) {
return NULL;
}
}