You are here

README.txt in YAML Content 8

-- Summary --

The YAML Content module provides a framework for defining content in a
human-readable and writable YAML structure allowing for the flexible
and straight-forward creation of demo content within a site.

-- REQUIREMENTS --

No additional modules are explicitly required for yaml_content to function.

-- INSTALLATION --

* Install as usual, see https://www.drupal.org/documentation/install/modules-themes/modules-8
  for further information.

-- SETUP --

Recommended setup for the module is to determine a target location for import
content to be found. Most accessibly, this could be within either an enabled
custom profile or module.

Within the target directory, content files may be created within a `content/`
subdirectory and follow the naming convention `*.content.yml`. Referenced images
or data files may also be added in parallel directories named `images/` and
`data_files` respectively.

-- USAGE --

Once content is created for import, it may be imported through the one of the
custom Drush commands:

- `drush yaml-content-import <directory>`
- `drush yaml-content-import-module <module_name>`
- `drush yaml-content-import-profile <profile_name>`

-- EXAMPLES --

For some brief content examples, have a look in the `content` folder of this
module. In that folder there are example import files with inline commentary
describing how values are set and the data is structured. These content files
may also be imported into a site with the matching architecture for a demonstration.
In the case of these files, any site installed using the Standard install profile
should have the required content types and field structure to support the demo
content.

To run the import, ensure the yaml_content module is enabled and run the following
command through Drush:

    drush yaml-content-import-module yaml_content

-- INSTALLATION PROFILE USAGE --

To trigger loading content during an installation profile just add an install
task.

/**
 * Implements hook_install_tasks().
 */
function MYPROFILE_install_tasks(&$install_state) {
  $tasks = [
    // Install the demo content using YAML Content.
    'MYPROFILE_install_content' => [
      'display_name' => t('Install demo content'),
      'type' => 'normal',
    ],
  ];

  return $tasks;
}

/**
 * Callback function to install demo content.
 *
 * @see MYPROFILE_install_tasks()
 */
function MYPROFILE_install_content() {
  // Create default content.
  $loader = \Drupal::service('yaml_content.load_helper');
  $loader->importProfile('MYPROFILE');

  // Set front page to the page loaded above.
  \Drupal::configFactory()
    ->getEditable('system.site')
    ->set('page.front', '/home')
    ->save(TRUE);
}

File

README.txt
View source
  1. -- Summary --
  2. The YAML Content module provides a framework for defining content in a
  3. human-readable and writable YAML structure allowing for the flexible
  4. and straight-forward creation of demo content within a site.
  5. -- REQUIREMENTS --
  6. No additional modules are explicitly required for yaml_content to function.
  7. -- INSTALLATION --
  8. * Install as usual, see https://www.drupal.org/documentation/install/modules-themes/modules-8
  9. for further information.
  10. -- SETUP --
  11. Recommended setup for the module is to determine a target location for import
  12. content to be found. Most accessibly, this could be within either an enabled
  13. custom profile or module.
  14. Within the target directory, content files may be created within a `content/`
  15. subdirectory and follow the naming convention `*.content.yml`. Referenced images
  16. or data files may also be added in parallel directories named `images/` and
  17. `data_files` respectively.
  18. -- USAGE --
  19. Once content is created for import, it may be imported through the one of the
  20. custom Drush commands:
  21. - `drush yaml-content-import `
  22. - `drush yaml-content-import-module `
  23. - `drush yaml-content-import-profile `
  24. -- EXAMPLES --
  25. For some brief content examples, have a look in the `content` folder of this
  26. module. In that folder there are example import files with inline commentary
  27. describing how values are set and the data is structured. These content files
  28. may also be imported into a site with the matching architecture for a demonstration.
  29. In the case of these files, any site installed using the Standard install profile
  30. should have the required content types and field structure to support the demo
  31. content.
  32. To run the import, ensure the yaml_content module is enabled and run the following
  33. command through Drush:
  34. drush yaml-content-import-module yaml_content
  35. -- INSTALLATION PROFILE USAGE --
  36. To trigger loading content during an installation profile just add an install
  37. task.
  38. /**
  39. * Implements hook_install_tasks().
  40. */
  41. function MYPROFILE_install_tasks(&$install_state) {
  42. $tasks = [
  43. // Install the demo content using YAML Content.
  44. 'MYPROFILE_install_content' => [
  45. 'display_name' => t('Install demo content'),
  46. 'type' => 'normal',
  47. ],
  48. ];
  49. return $tasks;
  50. }
  51. /**
  52. * Callback function to install demo content.
  53. *
  54. * @see MYPROFILE_install_tasks()
  55. */
  56. function MYPROFILE_install_content() {
  57. // Create default content.
  58. $loader = \Drupal::service('yaml_content.load_helper');
  59. $loader->importProfile('MYPROFILE');
  60. // Set front page to the page loaded above.
  61. \Drupal::configFactory()
  62. ->getEditable('system.site')
  63. ->set('page.front', '/home')
  64. ->save(TRUE);
  65. }