function drush_yaml_content_import in YAML Content 8.2
Same name and namespace in other branches
- 8 yaml_content.drush.inc \drush_yaml_content_import()
Import specified yaml content file(s).
@todo Implement file globbing for optional `$file` parameter.
Parameters
string $directory: The directory path containing the yaml content file(s) to be imported.
string|string[] $file: (Optional) The name of a file to be imported or an array of files to import. If this argument is not provided then all files in the directory matching `*.content.yml` are queued for import.
1 call to drush_yaml_content_import()
- drush_yaml_content_import_dev in ./
yaml_content.drush.inc - Import debugging content.
File
- ./
yaml_content.drush.inc, line 52 - Drush commands for the yaml_content module.
Code
function drush_yaml_content_import($directory, $file = NULL) {
$loader = \Drupal::service('yaml_content.content_loader');
$loader
->setContentPath($directory);
// @todo Implement file globbing if `$file` is NULL.
$import_files = is_array($file) ? $file : [
$file,
];
// @todo Verify files before loading for import.
foreach ($import_files as $file) {
drush_print_r('Importing content: ' . $file);
$loader
->parseContent($file);
$loaded = $loader
->loadContent();
drush_print_r('Imported ' . count($loaded) . ' items.');
}
}