FeaturesManagerInterface.php 20 KB

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