You are here

public static function RealisticDummyContentEnvironment::getAllFileGroups in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/includes/RealisticDummyContentEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentEnvironment::getAllFileGroups()
  2. 7.2 api/src/includes/RealisticDummyContentEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentEnvironment::getAllFileGroups()

Returns all files with a given extension for a given filepath.

Files do not always have a one-to-one relationship with the filesystem. For example:

1.txt 2.txt 3.txt

will be represented as three files, but

1.txt 2.txt 2.txt.attribute.txt 2.txt.attribute1.txt 3.txt

will also be represented as three files, but the second one will have two attributes, attribute and attribute1.

Parameters

string $filepath: An absolute filepath on the system, for example /path/to/drupal/sites/all/ modules/mymodule/realistic_dummy_content/fields/node/article/body.

array $extensions: An array of extensions which should be taken into consideration.

Return value

array An empty array in case of an error, or an array of objects of type RealisticDummyContentFileGroup.

1 call to RealisticDummyContentEnvironment::getAllFileGroups()
RealisticDummyContentAttribute::getCandidateFiles in api/src/includes/RealisticDummyContentAttribute.php
Get all candidate files for a given field for this entity.

File

api/src/includes/RealisticDummyContentEnvironment.php, line 148

Class

RealisticDummyContentEnvironment
The abstract base environment.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

public static function getAllFileGroups($filepath, array $extensions) {
  try {
    $candidate_files = \Drupal::service('file_system')
      ->scanDirectory($filepath, '/.*$/', [
      'key' => 'filename',
    ]);
    $files = self::sortCandidateFiles($candidate_files, $extensions);
    $return = [];
    foreach ($files as $radical => $attributes) {
      $return[] = new RealisticDummyContentFileGroup($radical, isset($attributes['file']) ? $attributes['file'] : NULL, isset($attributes['attributes']) ? $attributes['attributes'] : []);
    }
    return $return;
  } catch (\Throwable $e) {
    return [];
  }
}