You are here

public function RealisticDummyContentAttribute::valueFromFiles in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::valueFromFiles()
  2. 7.2 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 247

Class

RealisticDummyContentAttribute
Represents either a field or a property for an entity.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

public function valueFromFiles(array $files) {
  try {
    if (count($files)) {
      $rand_index = $this
        ->rand(0, count($files) - 1);
      $file = $files[$rand_index];
      return $this
        ->valueFromFile($file);
    }
  } catch (\Throwable $e) {
    return NULL;
  }
}