function ContentExport::listFolderFiles in Content Export YAML 8
File
- src/
ContentExport.php, line 432
Class
- ContentExport
- Created by PhpStorm. User: USER Date: 11/13/18 Time: 2:04 PM
Namespace
Drupal\content_export_yamlCode
function listFolderFiles($dir) {
$fileInfo = scandir($dir);
$allFileLists = [];
$parsed = new Parser();
foreach ($fileInfo as $folder) {
if ($folder !== '.' && $folder !== '..') {
if (is_dir($dir . DIRECTORY_SEPARATOR . $folder) === TRUE) {
$allFileLists[$folder] = $this
->listFolderFiles($dir . DIRECTORY_SEPARATOR . $folder);
}
else {
$path_file = $dir . DIRECTORY_SEPARATOR . $folder;
$ext = pathinfo($path_file, PATHINFO_EXTENSION);
if (file_exists($path_file) && $ext == 'yml') {
$item_yaml = file_get_contents($path_file, FILE_USE_INCLUDE_PATH);
if ($item_yaml) {
try {
$item_object = \Symfony\Component\Yaml\Yaml::parse($item_yaml, SymfonyYaml::PARSE_OBJECT);
} catch (Exception $e) {
\Drupal::messenger()
->addMessage(t('Message: ' . $e
->getMessage()), 'error');
}
if ($item_object && is_object($item_object)) {
$path = str_replace(DRUPAL_ROOT, "", $path_file);
$allFileLists[$folder] = [
"file" => $folder,
"path" => $path,
"entity" => $item_object,
];
}
}
}
}
}
}
return $allFileLists;
}