FeaturesGeneratorInterface.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Drupal\features;
  3. use Drupal\Core\Form\FormStateInterface;
  4. /**
  5. * Common interface for features generation services.
  6. *
  7. * The configuration packaging API is based on two major concepts:
  8. * - Packages: modules into which configuration is packaged.
  9. * - Package generation methods: responsible for `determining
  10. * which package to assign a given piece of configuration to.
  11. * Generation methods are customizable.
  12. *
  13. * Features defines two package generation methods, which are simple plugin
  14. * classes that implement a particular logic to assign pieces of configuration
  15. * to a given package (module).
  16. *
  17. * Modules can define additional package generation methods by simply providing
  18. * the related plugins, and alter existing methods through
  19. * hook_features_generation_method_info_alter(). Here is an example
  20. * snippet:
  21. * @code
  22. * function mymodule_features_generation_method_info_alter(&$generation_info) {
  23. * // Replace the original plugin with our own implementation.
  24. * $method_id = \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationArchive::METHOD_ID;
  25. * $generation_info[$method_id]['class'] = 'Drupal\my_module\Plugin\FeaturesGeneration\MyFeaturesGenerationArchive';
  26. * }
  27. *
  28. * class MyFeaturesGenerationArchive extends FeaturesGenerationArchive {
  29. * public function generate(array $packages = array(), FeaturesBundleInterface $bundle = NULL) {
  30. * // Insert customization here.
  31. * }
  32. * }
  33. * ?>
  34. * @endcode
  35. *
  36. * For more information, see
  37. * @link http://drupal.org/node/2404473 Developing for Features 3.x @endlink
  38. */
  39. interface FeaturesGeneratorInterface {
  40. /**
  41. * The package generation method id for the package generator itself.
  42. */
  43. const METHOD_ID = 'generator-default';
  44. /**
  45. * Resets the assigned packages and the method instances.
  46. */
  47. public function reset();
  48. /**
  49. * Apply a given package generation method.
  50. *
  51. * @param string $method_id
  52. * The string identifier of the package generation method to use to package
  53. * configuration.
  54. * @param array $packages
  55. * Array of package data.
  56. * @param \Drupal\features\FeaturesBundleInterface $bundle
  57. * The optional bundle used for the generation. Used to generate profiles.
  58. *
  59. * @return array
  60. * Array of results for profile and/or packages, each result including the
  61. * following keys:
  62. * - 'success': boolean TRUE or FALSE for successful writing.
  63. * - 'display': boolean TRUE if the message should be displayed to the
  64. * user, otherwise FALSE.
  65. * - 'message': a message about the result of the operation.
  66. * - 'variables': an array of substitutions to be used in the message.
  67. */
  68. public function applyGenerationMethod($method_id, array $packages = array(), FeaturesBundleInterface $bundle = NULL);
  69. /**
  70. * Responds to the submission of
  71. * \Drupal\features_ui\Form\FeaturesExportForm.
  72. */
  73. public function applyExportFormSubmit($method_id, &$form, FormStateInterface $form_state);
  74. /**
  75. * Returns the enabled package generation methods.
  76. *
  77. * @return array
  78. * An array of package generation method definitions keyed by method id.
  79. */
  80. public function getGenerationMethods();
  81. /**
  82. * Generates file representations of configuration packages.
  83. *
  84. * @param string $method_id
  85. * The ID of the generation method to use.
  86. * @param \Drupal\features\FeaturesBundleInterface $bundle
  87. * The bundle used for the generation.
  88. * @param array $package_names
  89. * Array of names of packages to be generated. If none are specified, all
  90. * available packages will be added.
  91. */
  92. public function generatePackages($method_id, FeaturesBundleInterface $bundle, array $package_names = array());
  93. }