FeaturesManagerInterface.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <?php
  2. namespace Drupal\features;
  3. use Drupal\Core\Extension\Extension;
  4. /**
  5. * Provides an interface for the FeaturesManager.
  6. */
  7. interface FeaturesManagerInterface {
  8. /**
  9. * Simple configuration.
  10. *
  11. * Core uses system.simple, but since we're using this key in configuration
  12. * arrays we can't include a period.
  13. *
  14. * @see https://www.drupal.org/node/2297311
  15. */
  16. const SYSTEM_SIMPLE_CONFIG = 'system_simple';
  17. /**
  18. * Constants for package/module status.
  19. */
  20. const STATUS_NO_EXPORT = 0;
  21. const STATUS_UNINSTALLED = 1;
  22. const STATUS_INSTALLED = 2;
  23. const STATUS_DEFAULT = self::STATUS_NO_EXPORT;
  24. /**
  25. * Constants for package/module state.
  26. */
  27. const STATE_DEFAULT = 0;
  28. const STATE_OVERRIDDEN = 1;
  29. /**
  30. * Returns the active config store.
  31. *
  32. * @return \Drupal\Core\Config\StorageInterface
  33. */
  34. public function getActiveStorage();
  35. /**
  36. * Returns a set of config storages.
  37. *
  38. * This method is used for support of multiple extension configuration
  39. * directories, including the core-provided install and optional directories.
  40. *
  41. * @return \Drupal\Core\Config\StorageInterface[]
  42. */
  43. public function getExtensionStorages();
  44. /**
  45. * Resets packages and configuration assignment.
  46. */
  47. public function reset();
  48. /**
  49. * Gets an array of site configuration.
  50. *
  51. * @param bool $reset
  52. * If TRUE, recalculate the configuration (undo all assignment methods).
  53. *
  54. * @return \Drupal\features\ConfigurationItem[]
  55. * An array of items, each with the following keys:
  56. * - 'name': prefixed configuration item name.
  57. * - 'name_short': configuration item name without prefix.
  58. * - 'label': human readable name of configuration item.
  59. * - 'type': type of configuration.
  60. * - 'data': the contents of the configuration item in exported format.
  61. * - 'dependents': array of names of dependent configuration items.
  62. * - 'subdirectory': feature subdirectory to export item to.
  63. * - 'package': machine name of a package the configuration is assigned to.
  64. * - 'extension_provided': whether the configuration is provided by an
  65. * extension.
  66. * - 'package_excluded': array of package names that this item should be
  67. * excluded from.
  68. */
  69. public function getConfigCollection($reset = FALSE);
  70. /**
  71. * Sets an array of site configuration.
  72. *
  73. * @param \Drupal\features\ConfigurationItem[] $config_collection
  74. * An array of items.
  75. */
  76. public function setConfigCollection(array $config_collection);
  77. /**
  78. * Gets an array of packages.
  79. *
  80. * @return \Drupal\features\Package[]
  81. * An array of items, each with the following keys:
  82. * - 'machine_name': machine name of the package such as 'example_article'.
  83. * 'article'.
  84. * - 'name': human readable name of the package such as 'Example Article'.
  85. * - 'description': description of the package.
  86. * - 'type': type of Drupal project ('module').
  87. * - 'core': Drupal core compatibility ('8.x').
  88. * - 'dependencies': array of module dependencies.
  89. * - 'themes': array of names of themes to install.
  90. * - 'config': array of names of configuration items.
  91. * - 'status': status of the package. Valid values are:
  92. * - FeaturesManagerInterface::STATUS_NO_EXPORT
  93. * - FeaturesManagerInterface::STATUS_INSTALLED
  94. * - FeaturesManagerInterface::STATUS_UNINSTALLED
  95. * - 'version': version of the extension.
  96. * - 'state': state of the extension. Valid values are:
  97. * - FeaturesManagerInterface::STATE_DEFAULT
  98. * - FeaturesManagerInterface::STATE_OVERRIDDEN
  99. * - 'directory': the extension's directory.
  100. * - 'files' array of files, each having the following keys:
  101. * - 'filename': the name of the file.
  102. * - 'subdirectory': any subdirectory of the file within the extension
  103. * directory.
  104. * - 'string': the contents of the file.
  105. * - 'bundle': name of the features bundle this package belongs to.
  106. * - 'extension': \Drupal\Core\Extension\Extension object.
  107. * - 'info': the original info array from an existing package.
  108. * - 'config_info': the original config of the module.
  109. *
  110. * @see \Drupal\features\FeaturesManagerInterface::setPackages()
  111. */
  112. public function getPackages();
  113. /**
  114. * Sets an array of packages.
  115. *
  116. * @param \Drupal\features\Package[] $packages
  117. * An array of packages.
  118. */
  119. public function setPackages(array $packages);
  120. /**
  121. * Gets a specific package.
  122. *
  123. * @param string $machine_name
  124. * Full machine name of package.
  125. *
  126. * @return \Drupal\features\Package
  127. * Package data.
  128. *
  129. * @see \Drupal\features\FeaturesManagerInterface::getPackages()
  130. */
  131. public function getPackage($machine_name);
  132. /**
  133. * Gets a specific package.
  134. * Similar to getPackage but will also match package FullName
  135. *
  136. * @param string $machine_name
  137. * Full machine name of package.
  138. *
  139. * @return \Drupal\features\Package
  140. * Package data.
  141. *
  142. * @see \Drupal\features\FeaturesManagerInterface::getPackages()
  143. */
  144. public function findPackage($machine_name);
  145. /**
  146. * Updates a package definition in the package list.
  147. *
  148. * NOTE: This does not "export" the package; it simply updates the internal
  149. * data.
  150. *
  151. * @param \Drupal\features\Package $package
  152. * The package.
  153. */
  154. public function setPackage(Package $package);
  155. /**
  156. * Filters the supplied package list by the given namespace.
  157. *
  158. * @param \Drupal\features\Package[] $packages
  159. * An array of packages.
  160. * @param string $namespace
  161. * The namespace to use.
  162. * @param bool $only_exported
  163. * If true, only filter out packages that are exported
  164. *
  165. * @return \Drupal\features\Package[]
  166. * An array of packages.
  167. */
  168. public function filterPackages(array $packages, $namespace = '', $only_exported = FALSE);
  169. /**
  170. * Gets a reference to a package assigner.
  171. *
  172. * @return \Drupal\features\FeaturesAssignerInterface
  173. * The package assigner.
  174. */
  175. public function getAssigner();
  176. /**
  177. * Injects the package assigner.
  178. *
  179. * @param \Drupal\features\FeaturesAssignerInterface $assigner
  180. * The package assigner.
  181. */
  182. public function setAssigner(FeaturesAssignerInterface $assigner);
  183. /**
  184. * Gets a reference to a package generator.
  185. *
  186. * @return \Drupal\features\FeaturesGeneratorInterface
  187. * The package generator.
  188. */
  189. public function getGenerator();
  190. /**
  191. * Injects the package generator.
  192. *
  193. * @param \Drupal\features\FeaturesGeneratorInterface $generator
  194. * The package generator.
  195. */
  196. public function setGenerator(FeaturesGeneratorInterface $generator);
  197. /**
  198. * Returns the current export settings.
  199. *
  200. * @return array
  201. * An array with the following keys:
  202. * - 'folder' - subdirectory to export packages to.
  203. * - 'namespace' - module namespace being exported.
  204. */
  205. public function getExportSettings();
  206. /**
  207. * Returns the current general features settings.
  208. *
  209. * @return \Drupal\Core\Config\Config
  210. * A config object containing settings.
  211. */
  212. public function getSettings();
  213. /**
  214. * Returns the contents of an extensions info.yml file.
  215. *
  216. * @param \Drupal\Core\Extension\Extension $extension
  217. * An Extension object.
  218. *
  219. * @return array
  220. * An array representing data in an info.yml file.
  221. */
  222. public function getExtensionInfo(Extension $extension);
  223. /**
  224. * Determine if extension is enabled
  225. *
  226. * @param \Drupal\Core\Extension\Extension $extension
  227. * @return bool
  228. */
  229. public function extensionEnabled(Extension $extension);
  230. /**
  231. * Initializes a configuration package.
  232. *
  233. * @param string $machine_name
  234. * Machine name of the package.
  235. * @param string $name
  236. * (optional) Human readable name of the package.
  237. * @param string $description
  238. * (optional) Description of the package.
  239. * @param string $type
  240. * (optional) Type of project.
  241. * @param \Drupal\features\FeaturesBundleInterface $bundle
  242. * (optional) Bundle to use to add profile directories to the scan.
  243. * @param \Drupal\Core\Extension\Extension $extension
  244. * (optional) An Extension object.
  245. * @return array
  246. * The created package array.
  247. */
  248. public function initPackage($machine_name, $name = NULL, $description = '', $type = 'module', FeaturesBundleInterface $bundle = NULL, Extension $extension = NULL);
  249. /**
  250. * Initializes a configuration package using module info data.
  251. *
  252. * @param \Drupal\Core\Extension\Extension $extension
  253. * An Extension object.
  254. *
  255. * @return \Drupal\features\Package
  256. * The created package array.
  257. */
  258. public function initPackageFromExtension(Extension $extension);
  259. /**
  260. * Lists directories in which packages are present.
  261. *
  262. * This method scans to find package modules whether or not they are
  263. * currently active (installed). As well as the directories that are
  264. * usually scanned for modules and profiles, a profile directory for the
  265. * current profile is scanned if it exists. For example, if the value
  266. * for $bundle->getProfileName() is 'example', a
  267. * directory profiles/example will be scanned if it exists. Therefore, when
  268. * regenerating package modules, existing ones from a prior export will be
  269. * recognized.
  270. *
  271. * @param string[] $machine_names
  272. * Package machine names to return directories for. If omitted, return all
  273. * directories.
  274. * @param \Drupal\features\FeaturesBundleInterface $bundle
  275. * Optional bundle to use to add profile directories to the scan.
  276. *
  277. * @return array
  278. * Array of package directories keyed by package machine name.
  279. */
  280. public function listPackageDirectories(array $machine_names = array(), FeaturesBundleInterface $bundle = NULL);
  281. /**
  282. * Assigns a set of configuration items to a given package or profile.
  283. *
  284. * @param string $package_name
  285. * Machine name of a package or the profile.
  286. * @param string[] $item_names
  287. * Configuration item names.
  288. * @param bool $force
  289. * (optional) If TRUE, assign config regardless of restrictions such as it
  290. * being already assigned to a package.
  291. *
  292. * @throws Exception
  293. */
  294. public function assignConfigPackage($package_name, array $item_names, $force = FALSE);
  295. /**
  296. * Assigns configuration items with names matching given strings to given
  297. * packages.
  298. *
  299. * @param array $patterns
  300. * Array with string patterns as keys and package machine names as values.
  301. */
  302. public function assignConfigByPattern(array $patterns);
  303. /**
  304. * For given configuration items, assigns any dependent configuration to the
  305. * same package.
  306. *
  307. * @param string[] $item_names
  308. * Configuration item names.
  309. * @param string $package
  310. * Short machine name of package to assign dependent config to. If NULL,
  311. * use the current package of the parent config items.
  312. */
  313. public function assignConfigDependents(array $item_names = NULL, $package = NULL);
  314. /**
  315. * Adds the optional bundle prefix to package machine names.
  316. *
  317. * @param \Drupal\features\FeaturesBundleInterface $bundle
  318. * The bundle used for the generation.
  319. * @param string[] &$package_names
  320. * (optional) Array of package names, passed by reference.
  321. */
  322. public function setPackageBundleNames(FeaturesBundleInterface $bundle, array &$package_names = []);
  323. /**
  324. * Assigns dependencies from config items into the package.
  325. *
  326. * @param \Drupal\features\Package[] $packages
  327. * An array of packages. NULL for all packages
  328. */
  329. public function assignPackageDependencies(Package $package = NULL);
  330. /**
  331. * Assigns dependencies between packages based on configuration dependencies.
  332. *
  333. * \Drupal\features\FeaturesBundleInterface::setPackageBundleNames() must be
  334. * called prior to calling this method.
  335. *
  336. * @param \Drupal\features\FeaturesBundleInterface $bundle
  337. * A features bundle.
  338. * @param \Drupal\features\Package[] $packages
  339. * An array of packages.
  340. */
  341. public function assignInterPackageDependencies(FeaturesBundleInterface $bundle, array &$packages);
  342. /**
  343. * Merges two info arrays and processes the resulting array.
  344. *
  345. * Ensures values are unique and sorted.
  346. *
  347. * @param array $info1
  348. * The first array.
  349. * @param array $info2
  350. * The second array.
  351. * @param string[] $keys
  352. * Keys to merge. If not specified, all keys present will be merged.
  353. *
  354. * @return array
  355. * An array with the merged and processed results.
  356. *
  357. * @fixme Should this be moved to the package object or a related helper?
  358. */
  359. public function mergeInfoArray(array $info1, array $info2, array $keys = array());
  360. /**
  361. * Lists the types of configuration available on the site.
  362. *
  363. * @param boolean $bundles_only
  364. * Whether to list only configuration types that provide bundles.
  365. *
  366. * @return array
  367. * An array with machine name keys and human readable values.
  368. */
  369. public function listConfigTypes($bundles_only = FALSE);
  370. /**
  371. * Lists stored configuration for a given configuration type.
  372. *
  373. * @param string $config_type
  374. * The type of configuration.
  375. */
  376. public function listConfigByType($config_type);
  377. /**
  378. * Returns a list of all modules present on the site's file system.
  379. *
  380. * @return Drupal\Core\Extension\Extension[]
  381. * An array of extension objects.
  382. */
  383. public function getAllModules();
  384. /**
  385. * Returns a list of Features modules regardless of if they are installed.
  386. *
  387. * @param \Drupal\features\FeaturesBundleInterface $bundle
  388. * Optional bundle to filter module list.
  389. * If given, only modules matching the bundle namespace will be returned.
  390. * If the bundle uses a profile, only modules in the profile will be
  391. * returned.
  392. * @param bool $installed
  393. * List only installed modules.
  394. *
  395. * @return Drupal\Core\Extension\Extension[]
  396. * An array of extension objects.
  397. */
  398. public function getFeaturesModules(FeaturesBundleInterface $bundle = NULL, $installed = FALSE);
  399. /**
  400. * Lists names of configuration objects provided by a given extension.
  401. *
  402. * @param \Drupal\Core\Extension\Extension $extension
  403. * An Extension object.
  404. *
  405. * @return array
  406. * An array of configuration object names.
  407. */
  408. public function listExtensionConfig(Extension $extension);
  409. /**
  410. * Lists names of configuration items provided by existing Features modules.
  411. *
  412. * @param bool $installed
  413. * List only installed Features.
  414. * @param \Drupal\features\FeaturesBundleInterface $bundle
  415. * (optional) Bundle to find existing configuration for.
  416. *
  417. * @return array
  418. * An array with config names as keys and providing module names as values.
  419. */
  420. public function listExistingConfig($installed = FALSE, FeaturesBundleInterface $bundle = NULL);
  421. /**
  422. * Iterates through packages and prepares file names and contents.
  423. *
  424. * @param array $packages
  425. * An array of packages.
  426. */
  427. public function prepareFiles(array $packages);
  428. /**
  429. * Returns the full name of a config item.
  430. *
  431. * @param string $type
  432. * The config type, or '' to indicate $name is already prefixed.
  433. * @param string $name
  434. * The config name, without prefix.
  435. *
  436. * @return string
  437. * The config item's full name.
  438. */
  439. public function getFullName($type, $name);
  440. /**
  441. * Returns the short name and type of a full config name.
  442. *
  443. * @param string $fullname
  444. * The full configuration name
  445. * @return array
  446. * 'type' => string the config type
  447. * 'name_short' => string the short config name, without prefix.
  448. */
  449. public function getConfigType($fullname);
  450. /**
  451. * Returns the full machine name and directory for exporting a package.
  452. *
  453. * @param \Drupal\features\Package $package
  454. * The package.
  455. * @param \Drupal\features\FeaturesBundleInterface $bundle
  456. * Optional bundle being used for export.
  457. *
  458. * @return array
  459. * An array with the full name as the first item and directory as second
  460. * item.
  461. */
  462. public function getExportInfo(Package $package, FeaturesBundleInterface $bundle = NULL);
  463. /**
  464. * Determines if the module is a Features package, optinally testing by
  465. * bundle.
  466. *
  467. * @param \Drupal\Core\Extension\Extension $module
  468. * An extension object.
  469. * @param \Drupal\features\FeaturesBundleInterface $bundle
  470. * (optional) Bundle to filter by.
  471. *
  472. * @return bool
  473. * TRUE if the given module is a Features package of the given bundle (if any).
  474. */
  475. public function isFeatureModule(Extension $module, FeaturesBundleInterface $bundle);
  476. /**
  477. * Determines which config is overridden in a package.
  478. *
  479. * @param \Drupal\features\Package $feature
  480. * The package array.
  481. * The 'state' property is updated if overrides are detected.
  482. * @param bool $include_new
  483. * If set, include newly detected config not yet exported.
  484. *
  485. * @result array $different
  486. * The array of config items that are overridden.
  487. *
  488. * @see \Drupal\features\FeaturesManagerInterface::detectNew()
  489. */
  490. public function detectOverrides(Package $feature, $include_new = FALSE);
  491. /**
  492. * Determines which config has not been exported to the feature.
  493. *
  494. * Typically added as an auto-detected dependency.
  495. *
  496. * @param \Drupal\features\Package $feature
  497. * The package array.
  498. *
  499. * @return array
  500. * The array of config items that are overridden.
  501. */
  502. public function detectNew(Package $feature);
  503. /**
  504. * Determines which config is exported in the feature but not in the active.
  505. *
  506. * @param \Drupal\features\Package $feature
  507. * The package array.
  508. *
  509. * @return array
  510. * The array of config items that are missing from active store.
  511. */
  512. public function detectMissing(Package $feature);
  513. /**
  514. * Sort the Missing config into order by dependencies.
  515. * @param array $missing config items
  516. * @return array of config items in dependency order
  517. */
  518. public function reorderMissing(array $missing);
  519. /**
  520. * Helper function that returns a translatable label for the different status
  521. * constants.
  522. *
  523. * @param int $status
  524. * A status constant.
  525. *
  526. * @return string
  527. * A translatable label.
  528. */
  529. public function statusLabel($status);
  530. /**
  531. * Helper function that returns a translatable label for the different state
  532. * constants.
  533. *
  534. * @param int $state
  535. * A state constant.
  536. *
  537. * @return string
  538. * A translatable label.
  539. */
  540. public function stateLabel($state);
  541. /**
  542. * @param \Drupal\Core\Extension\Extension $extension
  543. *
  544. * @return array
  545. */
  546. public function getFeaturesInfo(Extension $extension);
  547. }