FeaturesAssignerInterface.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. namespace Drupal\features;
  3. /**
  4. * Common interface for features assignment services.
  5. *
  6. * The feature API is based on two major concepts:
  7. * - Packages: modules into which configuration is packaged.
  8. * - Package assignment methods: responsible for `determining
  9. * which package to assign a given piece of configuration to.
  10. * Assignment methods are customizable.
  11. *
  12. * Features defines several package assignment methods, which are simple plugin
  13. * classes that implement a particular logic to assign pieces of configuration
  14. * to a given package (module).
  15. *
  16. * Modules can define additional package assignment methods by simply providing
  17. * the related plugins, and alter existing methods through
  18. * hook_features_assignment_method_info_alter(). Here is an example
  19. * snippet:
  20. * @code
  21. * function mymodule_features_assignment_method_info_alter(&$assignment_info) {
  22. * // Replace the original plugin with our own implementation.
  23. * $method_id = \Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentBaseType::METHOD_ID;
  24. * $assignment_info[$method_id]['class'] = 'Drupal\my_module\Plugin\FeaturesAssignment\MyFeaturesAssignmentBaseType';
  25. * }
  26. *
  27. * class MyFeaturesAssignmentBaseType extends FeaturesAssignmentBaseType {
  28. * public function assignPackages($force = FALSE) {
  29. * // Insert customization here.
  30. * }
  31. * }
  32. * ?>
  33. * @endcode
  34. *
  35. * For more information, see
  36. * @link http://drupal.org/node/2404473 Developing for Features 3.x @endlink
  37. */
  38. interface FeaturesAssignerInterface {
  39. /**
  40. * The package assignment method id for the package assigner itself.
  41. */
  42. const METHOD_ID = 'assigner-default';
  43. /**
  44. * Resets the assigned packages and the method instances.
  45. */
  46. public function reset();
  47. /**
  48. * Apply all enabled package assignment methods.
  49. *
  50. * @param bool $force
  51. * (optional) If TRUE, assign config regardless of restrictions such as it
  52. * being already assigned to a package.
  53. */
  54. public function assignConfigPackages($force = FALSE);
  55. /**
  56. * Applies a given package assignment method.
  57. *
  58. * @param string $method_id
  59. * The string identifier of the package assignment method to use to package
  60. * configuration.
  61. * @param bool $force
  62. * (optional) If TRUE, assign config regardless of restrictions such as it
  63. * being already assigned to a package.
  64. */
  65. public function applyAssignmentMethod($method_id, $force = FALSE);
  66. /**
  67. * Returns the enabled package assignment methods.
  68. *
  69. * @return array
  70. * An array of package assignment method IDs.
  71. */
  72. public function getAssignmentMethods();
  73. /**
  74. * Resaves the configuration to purge missing assignment methods.
  75. */
  76. public function purgeConfiguration();
  77. /**
  78. * Returns a FeaturesBundle object.
  79. *
  80. * @param string $name
  81. * machine name of package set. If omitted, returns the current bundle.
  82. *
  83. * @return \Drupal\features\FeaturesBundleInterface
  84. * A features bundle object.
  85. */
  86. public function getBundle($name = NULL);
  87. /**
  88. * Stores a features bundle.
  89. *
  90. * Added to list if machine_name is new.
  91. *
  92. * @param \Drupal\features\FeaturesBundleInterface $bundle
  93. * A features bundle.
  94. * @param bool $current
  95. * Determine if the current bundle is set to $bundle.
  96. * If False, the current bundle is only updated if it already has the same
  97. * machine name as the $bundle.
  98. */
  99. public function setBundle(FeaturesBundleInterface $bundle, $current = TRUE);
  100. /**
  101. * Searches for a bundle that matches the $info.yml or $features.yml export.
  102. *
  103. * Creates a new bundle as needed.
  104. *
  105. * @param array $info
  106. * The bundle info.
  107. * @param mixed $features_info
  108. * The features info.
  109. *
  110. * @return \Drupal\features\FeaturesBundleInterface
  111. * A bundle.
  112. */
  113. public function findBundle(array $info, $features_info = NULL);
  114. /**
  115. * Sets the currently active bundle.
  116. *
  117. * Updates value in current SESSION.
  118. *
  119. * @param \Drupal\features\FeaturesBundleInterface $bundle
  120. * A features bundle object.
  121. */
  122. public function setCurrent(FeaturesBundleInterface $bundle);
  123. /**
  124. * Returns an array of all existing features bundles.
  125. *
  126. * @return \Drupal\features\FeaturesBundleInterface[]
  127. * Keyed by machine_name with value of
  128. * \Drupal\features\FeaturesBundleInterface.
  129. */
  130. public function getBundleList();
  131. /**
  132. * Returns a named bundle.
  133. *
  134. * First searches by Human name, then by machine_name.
  135. *
  136. * @param string $name
  137. * The bundle name to search by.
  138. *
  139. * @return \Drupal\features\FeaturesBundleInterface
  140. * A features bundle object.
  141. */
  142. public function findBundleByName($name);
  143. /**
  144. * Creates a new bundle by duplicating the default bundle and customizing.
  145. *
  146. * @param string $machine_name
  147. * Machine name.
  148. * @param string $name
  149. * (optional) Human readable name of the bundle.
  150. * @param string $description
  151. * (optional) Description of the bundle.
  152. * @param bool $is_profile
  153. * (optional) TRUE if a profile is used with this bundle.
  154. * @param string $profile_name
  155. * (optional) The machine name of the profile.
  156. *
  157. * @return \Drupal\features\FeaturesBundleInterface
  158. * A features bundle object.
  159. */
  160. public function createBundleFromDefault($name, $machine_name = '', $description = '', $is_profile = FALSE, $profile_name = NULL);
  161. /**
  162. * Creates bundles by parsing information from installed packages.
  163. */
  164. public function createBundlesFromPackages();
  165. /**
  166. * Returns an array of bundle names suitable for a select option list.
  167. *
  168. * @return array
  169. * An array of bundles, keyed by machine_name, with values being human
  170. * readable names.
  171. */
  172. public function getBundleOptions();
  173. /**
  174. * Makes the named bundle the current bundle.
  175. *
  176. * @param string $machine_name
  177. * The name of a features bundle. If omitted, gets the last bundle from the
  178. * Session.
  179. *
  180. * @return \Drupal\features\FeaturesBundleInterface
  181. * A features bundle object.
  182. */
  183. public function applyBundle($machine_name = NULL);
  184. /**
  185. * Renames a bundle.
  186. *
  187. * @param string $old_machine
  188. * The old machine name of a bundle.
  189. * @param string $new_machine
  190. * The new machine name of a bundle.
  191. *
  192. * @return \Drupal\features\FeaturesBundleInterface
  193. * A features bundle object.
  194. */
  195. public function renameBundle($old_machine, $new_machine);
  196. /**
  197. * Loads a named bundle.
  198. *
  199. * @param string $machine_name
  200. * (optional) The name of a features bundle.
  201. * Defaults to NULL, gets the last bundle from the session.
  202. *
  203. * @return \Drupal\features\FeaturesBundleInterface
  204. * A features bundle object.
  205. */
  206. public function loadBundle($machine_name = NULL);
  207. }