features.module

  1. cis7 sites/all/modules/ulmus/features/features.module
  2. cle7 sites/all/modules/ulmus/features/features.module
  3. ecd7 sites/all/modules/ulmus/features/features.module
  4. elmsmedia7 sites/all/modules/ulmus/features/features.module
  5. harmony7 sites/all/modules/ulmus/features/features.module
  6. icor7 sites/all/modules/ulmus/features/features.module
  7. meedjum_blog7 sites/all/modules/ulmus/features/features.module
  8. mooc7 sites/all/modules/ulmus/features/features.module

Module file for the features module, which enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together satisfy a certain use-case.

Functions

Namesort descending Description
features_access_override_actions Menu access callback for whether a user should be able to access override actions for a given feature.
features_array_diff_assoc_recursive Recursively computes the difference of arrays with additional index check.
features_flush_caches Implements hook_flush_caches().
features_form Implements hook_form().
features_form_system_modules_alter Implements hook_form_alter() for system_modules form().
features_get_components Returns the array of supported components.
features_get_component_map Provide a component to feature map.
features_get_conflicts Detect potential conflicts between any features that provide identical components.
features_get_deprecated Returns an array of deprecated components Rather than deprecating the component directly, we look for other components that supersedes the component
features_get_features Wrapper around features_get_info() that returns an array of module info objects that are features.
features_get_feature_components Returns components that are offered as an option on feature creation.
features_get_feature_title Menu title callback.
features_get_info Helper for retrieving info from system table.
features_get_modules Return a module 'object' including .info information.
features_get_module_status Simple wrapper returns the status of a module.
features_get_orphans Generate an array of feature dependencies that have been orphaned.
features_help Implements hook_help().
features_hook Checks whether a component implements the given hook.
features_hook_info Implements hook_hook_info().
features_include Load includes for any modules that implement the features API and load includes for those provided by features.
features_include_defaults Load features includes for all components that require includes before collecting defaults.
features_install_modules Enables and installs an array of modules, ignoring those already enabled & installed. Consider this a helper or extension to drupal_install_modules().
features_invoke Invoke a component callback.
features_load_feature Feature object loader.
features_log Log a message, environment agnostic.
features_menu Implements hook_menu().
features_modules_disabled Implements hook_modules_disabled().
features_modules_enabled Implements hook_modules_enabled().
features_permission Implements hook_permission().
features_rebuild Wrapper around _features_restore().
features_revert Wrapper around _features_restore().
features_revert_module Revert a single features module.
features_theme Implements hook_theme().
feature_load Feature object loader. DEPRECATED but included for backwards compatibility
_features_restore Restore the specified modules to the default state.
_user_features_change_term_permission Change vocabularies permission, from vocab id to machine name and vice versa.

Constants

Namesort descending Description
FEATURES_ALTER_TYPE_INLINE
FEATURES_ALTER_TYPE_NONE
FEATURES_ALTER_TYPE_NORMAL
FEATURES_API
FEATURES_CHECKING
FEATURES_CONFLICT
FEATURES_DEFAULT
FEATURES_DEFAULTS_CUSTOM Components with this 'default_file' flag must specify a filename for their exports. Additionally a stub will NOT be written to 'MODULENAME.features.inc' allowing the file to be included directly by the implementing module.
FEATURES_DEFAULTS_INCLUDED Components with this 'default_file' flag will have exports written to a defaults based on the component name like 'MODULENAME.features.COMPONENT-NAME.inc'. Any callers to this component's defaults hook must…
FEATURES_DEFAULTS_INCLUDED_COMMON Components with this 'default_file' flag will have exports written to the common defaults file 'MODULENAME.features.inc'. This is the default behavior.
FEATURES_DEFAULT_EXPORT_PATH The default destination path for features exported via the UI.
FEATURES_DISABLED
FEATURES_DUPLICATES_ALLOWED Components with this 'duplicates' flag are allowed to have multiple features provide the same component key in their info files.
FEATURES_DUPLICATES_CONFLICT Components with this 'duplicates' flag may not have multiple features provide the same component key in their info files. This is the default behavior.
FEATURES_MODULE_CONFLICT
FEATURES_MODULE_DISABLED
FEATURES_MODULE_ENABLED
FEATURES_MODULE_MISSING
FEATURES_NEEDS_REVIEW
FEATURES_OVERRIDDEN
FEATURES_REBUILDABLE
FEATURES_REBUILDING
FEATURES_SEMAPHORE_TIMEOUT

File

sites/all/modules/ulmus/features/features.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Module file for the features module, which enables the capture and
  5. * management of features in Drupal. A feature is a collection of Drupal
  6. * entities which taken together satisfy a certain use-case.
  7. */
  8. define('FEATURES_API', '2');
  9. define('FEATURES_MODULE_ENABLED', 1);
  10. define('FEATURES_MODULE_DISABLED', 0);
  11. define('FEATURES_MODULE_MISSING', -1);
  12. define('FEATURES_MODULE_CONFLICT', 2);
  13. define('FEATURES_REBUILDABLE', -1);
  14. define('FEATURES_DEFAULT', 0);
  15. define('FEATURES_OVERRIDDEN', 1);
  16. define('FEATURES_NEEDS_REVIEW', 2);
  17. define('FEATURES_REBUILDING', 3);
  18. define('FEATURES_CONFLICT', 4);
  19. define('FEATURES_DISABLED', 5);
  20. define('FEATURES_CHECKING', 6);
  21. define('FEATURES_ALTER_TYPE_NORMAL', 'normal');
  22. define('FEATURES_ALTER_TYPE_INLINE', 'inline');
  23. define('FEATURES_ALTER_TYPE_NONE', 'none');
  24. // Duration of rebuild semaphore: 10 minutes.
  25. define('FEATURES_SEMAPHORE_TIMEOUT', 10 * 60);
  26. /**
  27. * Components with this 'default_file' flag will have exports written to the
  28. * common defaults file 'MODULENAME.features.inc'. This is the default
  29. * behavior.
  30. */
  31. define('FEATURES_DEFAULTS_INCLUDED_COMMON', 0);
  32. /**
  33. * Components with this 'default_file' flag will have exports written to a
  34. * defaults based on the component name like 'MODULENAME.features.COMPONENT-NAME.inc'.
  35. * Any callers to this component's defaults hook must call
  36. * features_include_defaults('component') in order to include this file.
  37. */
  38. define('FEATURES_DEFAULTS_INCLUDED', 1);
  39. /**
  40. * Components with this 'default_file' flag must specify a filename for their
  41. * exports. Additionally a stub will NOT be written to 'MODULENAME.features.inc'
  42. * allowing the file to be included directly by the implementing module.
  43. */
  44. define('FEATURES_DEFAULTS_CUSTOM', 2);
  45. /**
  46. * Components with this 'duplicates' flag may not have multiple features provide the
  47. * same component key in their info files. This is the default behavior.
  48. */
  49. define('FEATURES_DUPLICATES_CONFLICT', 0);
  50. /**
  51. * Components with this 'duplicates' flag are allowed to have multiple features
  52. * provide the same component key in their info files.
  53. */
  54. define('FEATURES_DUPLICATES_ALLOWED', 1);
  55. /**
  56. * The default destination path for features exported via the UI.
  57. */
  58. define('FEATURES_DEFAULT_EXPORT_PATH', 'sites/all/modules');
  59. /**
  60. * Implements hook_menu().
  61. */
  62. function features_menu() {
  63. $items = array();
  64. $items['admin/structure/features'] = array(
  65. 'title' => 'Features',
  66. 'description' => 'Manage features.',
  67. 'page callback' => 'drupal_get_form',
  68. 'page arguments' => array('features_admin_form'),
  69. 'type' => MENU_NORMAL_ITEM,
  70. 'file' => 'features.admin.inc',
  71. );
  72. $items['admin/structure/features/cleanup'] = array(
  73. 'title' => 'Cleanup',
  74. 'description' => 'Clear cache after enabling/disabling a feature.',
  75. 'page callback' => 'drupal_get_form',
  76. 'page arguments' => array('features_cleanup_form', 4),
  77. 'type' => MENU_CALLBACK,
  78. 'file' => 'features.admin.inc',
  79. 'weight' => 1,
  80. );
  81. $items['admin/structure/features/manage'] = array(
  82. 'title' => 'Manage',
  83. 'description' => 'Enable and disable features.',
  84. 'page callback' => 'drupal_get_form',
  85. 'page arguments' => array('features_admin_form'),
  86. 'type' => MENU_DEFAULT_LOCAL_TASK,
  87. 'file' => 'features.admin.inc',
  88. );
  89. $items['admin/structure/features/create'] = array(
  90. 'title' => 'Create feature',
  91. 'description' => 'Create a new feature.',
  92. 'page callback' => 'drupal_get_form',
  93. 'page arguments' => array('features_export_form'),
  94. 'access callback' => 'user_access',
  95. 'access arguments' => array('administer features'),
  96. 'type' => MENU_LOCAL_TASK,
  97. 'file' => "features.admin.inc",
  98. 'weight' => 10,
  99. );
  100. $items['admin/structure/features/settings'] = array(
  101. 'title' => 'Settings',
  102. 'description' => 'Adjust settings for using features module.',
  103. 'page callback' => 'drupal_get_form',
  104. 'page arguments' => array('features_settings_form'),
  105. 'access callback' => 'user_access',
  106. 'access arguments' => array('administer features'),
  107. 'type' => MENU_LOCAL_TASK,
  108. 'file' => "features.admin.inc",
  109. 'weight' => 11,
  110. );
  111. $items['admin/structure/features/%feature'] = array(
  112. 'title callback' => 'features_get_feature_title',
  113. 'title arguments' => array(3),
  114. 'description' => 'Display components of a feature.',
  115. 'page callback' => 'drupal_get_form',
  116. 'page arguments' => array('features_admin_components', 3),
  117. 'load arguments' => array(3, TRUE),
  118. 'access callback' => 'user_access',
  119. 'access arguments' => array('administer features'),
  120. 'type' => MENU_CALLBACK,
  121. 'file' => 'features.admin.inc',
  122. );
  123. $items['admin/structure/features/%feature/view'] = array(
  124. 'title' => 'View',
  125. 'description' => 'Display components of a feature.',
  126. 'access callback' => 'user_access',
  127. 'access arguments' => array('administer features'),
  128. 'type' => MENU_DEFAULT_LOCAL_TASK,
  129. 'weight' => -10,
  130. );
  131. $items['admin/structure/features/%feature/recreate'] = array(
  132. 'title' => 'Recreate',
  133. 'description' => 'Recreate an existing feature.',
  134. 'page callback' => 'drupal_get_form',
  135. 'page arguments' => array('features_export_form', 3),
  136. 'load arguments' => array(3, TRUE),
  137. 'access callback' => 'user_access',
  138. 'access arguments' => array('administer features'),
  139. 'type' => MENU_LOCAL_TASK,
  140. 'file' => "features.admin.inc",
  141. 'weight' => 11,
  142. );
  143. if (module_exists('diff')) {
  144. $items['admin/structure/features/%feature/diff'] = array(
  145. 'title' => 'Review overrides',
  146. 'description' => 'Compare default and current feature.',
  147. 'page callback' => 'features_feature_diff',
  148. 'page arguments' => array(3, 5),
  149. 'load arguments' => array(3, TRUE),
  150. 'access callback' => 'features_access_override_actions',
  151. 'access arguments' => array(3),
  152. 'type' => MENU_LOCAL_TASK,
  153. 'file' => 'features.admin.inc',
  154. );
  155. }
  156. $items['admin/structure/features/%feature/status'] = array(
  157. 'title' => 'Status',
  158. 'description' => 'Javascript status call back.',
  159. 'page callback' => 'features_feature_status',
  160. 'page arguments' => array(3),
  161. 'load arguments' => array(3, TRUE),
  162. 'access callback' => 'user_access',
  163. 'access arguments' => array('administer features'),
  164. 'type' => MENU_CALLBACK,
  165. 'file' => 'features.admin.inc',
  166. );
  167. $items['features/autocomplete/packages'] = array(
  168. 'page callback' => 'features_autocomplete_packages',
  169. 'access arguments' => array('administer features'),
  170. 'type' => MENU_CALLBACK,
  171. 'file' => 'features.admin.inc',
  172. );
  173. $items['features/ajaxcallback/%'] = array(
  174. 'title callback' => 'features_get_feature_components',
  175. 'description' => 'Return components of a feature.',
  176. 'page callback' => 'features_export_components_json',
  177. 'page arguments' => array(2),
  178. 'access callback' => 'user_access',
  179. 'access arguments' => array('administer features'),
  180. 'type' => MENU_CALLBACK,
  181. 'file' => 'features.admin.inc',
  182. );
  183. foreach ($items as $path => $item) {
  184. if (!isset($item['access callback'])) {
  185. $items[$path]['access callback'] = 'user_access';
  186. $items[$path]['access arguments'] = array('manage features');
  187. }
  188. }
  189. return $items;
  190. }
  191. /**
  192. * Implements hook_theme().
  193. */
  194. function features_theme() {
  195. $base = array(
  196. 'path' => drupal_get_path('module', 'features') . '/theme',
  197. 'file' => 'theme.inc',
  198. );
  199. $items = array();
  200. $items['features_module_status'] = array(
  201. 'variables' => array('module' => null, 'status' => null)
  202. ) + $base;
  203. $items['features_components'] = array(
  204. 'variables' => array('info' => null, 'sources' => null),
  205. ) + $base;
  206. $items['features_component_key'] = $base;
  207. $items['features_component_list'] = array(
  208. 'variables' => array('components' => array(), 'source' => array(), 'conflicts' => array()),
  209. ) + $base;
  210. $items['features_storage_link'] = array(
  211. 'variables' => array('storage' => null, 'text' => null, 'path' => null, 'options' => array()),
  212. ) + $base;
  213. $items['features_form_components'] =
  214. $items['features_form_export'] =
  215. $items['features_form_package'] = array(
  216. 'render element' => 'form',
  217. ) + $base;
  218. $items['features_form_buttons'] = array(
  219. 'render element' => 'element',
  220. ) + $base;
  221. $items['features_admin_components'] = array(
  222. 'render element' => 'form',
  223. 'template' => 'features-admin-components',
  224. ) + $base;
  225. return $items;
  226. }
  227. /**
  228. * Implements hook_flush_caches().
  229. */
  230. function features_flush_caches() {
  231. if (variable_get('features_rebuild_on_flush', TRUE)) {
  232. features_rebuild();
  233. // Don't flush the modules cache during installation, for performance reasons.
  234. if (variable_get('install_task') == 'done') {
  235. features_get_modules(NULL, TRUE);
  236. }
  237. }
  238. return array();
  239. }
  240. /**
  241. * Implements hook_form().
  242. */
  243. function features_form($node, $form_state) {
  244. return node_content_form($node, $form_state);
  245. }
  246. /**
  247. * Implements hook_permission().
  248. */
  249. function features_permission() {
  250. return array(
  251. 'administer features' => array(
  252. 'title' => t('Administer features'),
  253. 'description' => t('Perform administration tasks on features.'),
  254. 'restrict access' => TRUE,
  255. ),
  256. 'manage features' => array(
  257. 'title' => t('Manage features'),
  258. 'description' => t('View, enable and disable features.'),
  259. 'restrict access' => TRUE,
  260. ),
  261. 'generate features' => array(
  262. 'title' => t('Generate features'),
  263. 'description' => t('Allow feature exports to be generated and written directly to site.'),
  264. 'restrict access' => TRUE,
  265. ),
  266. );
  267. }
  268. /**
  269. * Implements hook_help().
  270. */
  271. function features_help($path, $arg) {
  272. switch ($path) {
  273. case 'admin/help#features':
  274. $output = file_get_contents(drupal_get_path('module', 'features') .'/README.txt');
  275. return module_exists('markdown') ? filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output)) : '<pre>'. check_plain($output) .'</pre>';
  276. case 'admin/build/features':
  277. return '<p>'. t('A "Feature" is a certain type of Drupal module which contains a package of configuration that, when enabled, provides a new set of functionality for your Drupal site. Enable features by selecting the checkboxes below and clicking the Save configuration button. If the configuration of the feature has been changed its "State" will be either "overridden" or "needs review", otherwise it will be "default", indicating that the configuration has not been changed. Click on the state to see more details about the feature and its components.') .'</p>';
  278. }
  279. }
  280. /**
  281. * Implements hook_modules_disabled().
  282. */
  283. function features_modules_disabled($modules) {
  284. // Go through all modules and gather features that can be disabled.
  285. $items = array();
  286. foreach ($modules as $module) {
  287. if ($feature = features_load_feature($module)) {
  288. $items[$module] = array_keys($feature->info['features']);
  289. }
  290. }
  291. if (!empty($items)) {
  292. _features_restore('disable', $items);
  293. // Rebuild the list of features includes.
  294. features_include(TRUE);
  295. }
  296. }
  297. /**
  298. * Implements hook_modules_enabled().
  299. */
  300. function features_modules_enabled($modules) {
  301. // Go through all modules and gather features that can be enabled.
  302. $items = array();
  303. foreach ($modules as $module) {
  304. if ($feature = features_load_feature($module)) {
  305. $items[$module] = array_keys($feature->info['features']);
  306. }
  307. }
  308. if (!empty($items)) {
  309. // Need to include any new files.
  310. // @todo Redo function so can take in list of modules to include.
  311. features_include_defaults(NULL, TRUE);
  312. _features_restore('enable', $items);
  313. // Rebuild the list of features includes.
  314. features_include(TRUE);
  315. // Reorders components to match hook order and removes non-existant.
  316. $all_components = array_keys(features_get_components());
  317. foreach ($items as $module => $components) {
  318. $items[$module] = array_intersect($all_components, $components);
  319. }
  320. _features_restore('rebuild', $items);
  321. }
  322. }
  323. /**
  324. * Load includes for any modules that implement the features API and
  325. * load includes for those provided by features.
  326. */
  327. function features_include($reset = FALSE) {
  328. static $once;
  329. if (!isset($once) || $reset) {
  330. $once = TRUE;
  331. // Features provides integration on behalf of these modules.
  332. // The features include provides handling for the feature dependencies.
  333. // Note that ctools is placed last because it implements hooks "dynamically" for other modules.
  334. $modules = array('features', 'block', 'context', 'field', 'filter', 'image', 'locale', 'menu', 'node', 'taxonomy', 'user', 'views', 'ctools');
  335. foreach (array_filter($modules, 'module_exists') as $module) {
  336. module_load_include('inc', 'features', "includes/features.$module");
  337. }
  338. if (module_exists('ctools')) {
  339. // Finally, add ctools eval'd implementations.
  340. ctools_features_declare_functions($reset);
  341. }
  342. // Clear static cache, since we've now included new implementers.
  343. foreach (features_get_components(NULL, 'file', $reset) as $file) {
  344. if (is_file(DRUPAL_ROOT . '/' . $file)) {
  345. require_once DRUPAL_ROOT . '/' . $file;
  346. }
  347. }
  348. }
  349. }
  350. /**
  351. * Load features includes for all components that require includes before
  352. * collecting defaults.
  353. */
  354. function features_include_defaults($components = NULL, $reset = FALSE) {
  355. static $include_components;
  356. // Build an array of components that require inclusion:
  357. // Views, CTools components and those using FEATURES_DEFAULTS_INCLUDED.
  358. if (!isset($include_components) || $reset) {
  359. $include_components = features_get_components();
  360. foreach ($include_components as $component => $info) {
  361. if (!isset($info['api']) && (!isset($info['default_file']) || $info['default_file'] !== FEATURES_DEFAULTS_INCLUDED)) {
  362. unset($include_components[$component]);
  363. }
  364. }
  365. }
  366. // If components are specified, only include for the specified components.
  367. if (isset($components)) {
  368. $components = is_array($components) ? $components : array($components);
  369. }
  370. // Use all include components if none are explicitly specified.
  371. else {
  372. $components = array_keys($include_components);
  373. }
  374. foreach ($components as $component) {
  375. if (isset($include_components[$component])) {
  376. $info = $include_components[$component];
  377. // Inclusion of ctools components.
  378. if (isset($info['api'], $info['module'], $info['current_version'])) {
  379. ctools_include('plugins');
  380. ctools_plugin_api_include($info['module'], $info['api'], $info['current_version'], $info['current_version']);
  381. }
  382. // Inclusion of defaults for components using FEATURES_DEFAULTS_INCLUDED.
  383. else {
  384. $features = isset($features) ? $features : features_get_features(NULL, $reset);
  385. foreach ($features as $feature) {
  386. $filename = isset($info['default_file']) && $info['default_file'] == FEATURES_DEFAULTS_CUSTOM ? $info['default_filename'] : "features.{$component}";
  387. if (module_exists($feature->name) && isset($feature->info['features'][$component])) {
  388. module_load_include('inc', $feature->name, "{$feature->name}.$filename");
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }
  395. /**
  396. * Feature object loader. DEPRECATED but included for backwards compatibility
  397. */
  398. function feature_load($name, $reset = FALSE) {
  399. return features_load_feature($name, $reset);
  400. }
  401. /**
  402. * Feature object loader.
  403. */
  404. function features_load_feature($name, $reset = FALSE) {
  405. // Use an alternative code path during installation, for better performance.
  406. if (variable_get('install_task') != 'done') {
  407. static $features;
  408. if (!isset($features[$name])) {
  409. // Set defaults for module info.
  410. $defaults = array(
  411. 'dependencies' => array(),
  412. 'description' => '',
  413. 'package' => 'Other',
  414. 'version' => NULL,
  415. 'php' => DRUPAL_MINIMUM_PHP,
  416. 'files' => array(),
  417. 'bootstrap' => 0,
  418. );
  419. $info = drupal_parse_info_file(drupal_get_path('module', $name) . '/' . $name . '.info');
  420. $features[$name] = FALSE;
  421. if (!empty($info['features']) && empty($info['hidden'])) {
  422. // Build a fake file object with the data needed during installation.
  423. $features[$name] = new stdClass;
  424. $features[$name]->name = $name;
  425. $features[$name]->filename = drupal_get_path('module', $name) . '/' . $name . '.module';
  426. $features[$name]->type = 'module';
  427. $features[$name]->info = $info + $defaults;
  428. }
  429. }
  430. return $features[$name];
  431. }
  432. else {
  433. return features_get_features($name, $reset);
  434. }
  435. }
  436. /**
  437. * Return a module 'object' including .info information.
  438. *
  439. * @param $name
  440. * The name of the module to retrieve information for. If ommitted,
  441. * an array of all available modules will be returned.
  442. * @param $reset
  443. * Whether to reset the cache.
  444. *
  445. * @return
  446. * If a module is request (and exists) a module object is returned. If no
  447. * module is requested info for all modules is returned.
  448. */
  449. function features_get_modules($name = NULL, $reset = FALSE) {
  450. return features_get_info('module', $name, $reset);
  451. }
  452. /**
  453. * Returns the array of supported components.
  454. *
  455. * @see hook_features_api
  456. *
  457. * @param $component
  458. * A specific type of component that supports features.
  459. * @param $key
  460. * A key that hook_features_api supports.
  461. *
  462. * @return An array of component labels keyed by the component names.
  463. */
  464. function features_get_components($component = NULL, $key = NULL, $reset = FALSE) {
  465. features_include();
  466. $components = &drupal_static(__FUNCTION__);
  467. $component_by_key = &drupal_static(__FUNCTION__ . '_by_key');
  468. if ($reset || !isset($components) || !isset($component_by_key)) {
  469. $components = $component_by_key = array();
  470. if (!$reset && ($cache = cache_get('features_api'))) {
  471. $components = $cache->data;
  472. }
  473. else {
  474. $components = module_invoke_all('features_api');
  475. drupal_alter('features_api', $components);
  476. cache_set('features_api', $components);
  477. }
  478. foreach ($components as $component_type => $component_information) {
  479. foreach ($component_information as $component_key => $component_value) {
  480. $component_by_key[$component_key][$component_type] = $component_value;
  481. }
  482. }
  483. }
  484. if ($key && $component) {
  485. return !empty($components[$component][$key]) ? $components[$component][$key] : NULL;
  486. }
  487. elseif ($key) {
  488. return !empty($component_by_key[$key]) ? $component_by_key[$key] : array();
  489. }
  490. elseif ($component) {
  491. return $components[$component];
  492. }
  493. return $components;
  494. }
  495. /**
  496. * Returns components that are offered as an option on feature creation.
  497. */
  498. function features_get_feature_components() {
  499. return array_intersect_key(features_get_components(), array_filter(features_get_components(NULL, 'feature_source')));
  500. }
  501. /**
  502. * Invoke a component callback.
  503. */
  504. function features_invoke($component, $callback) {
  505. $args = func_get_args();
  506. unset($args[0], $args[1]);
  507. // Append the component name to the arguments.
  508. $args[] = $component;
  509. if ($function = features_hook($component, $callback)) {
  510. return call_user_func_array($function, $args);
  511. }
  512. }
  513. /**
  514. * Checks whether a component implements the given hook.
  515. *
  516. * @return
  517. * The function implementing the hook, or FALSE.
  518. */
  519. function features_hook($component, $hook, $reset = FALSE) {
  520. // Determine the function callback base.
  521. $base = features_get_components($component, 'base');
  522. $base = isset($base) ? $base : $component;
  523. return function_exists($base . '_' . $hook) ? $base . '_' . $hook : FALSE;
  524. }
  525. /**
  526. * Enables and installs an array of modules, ignoring those
  527. * already enabled & installed. Consider this a helper or
  528. * extension to drupal_install_modules().
  529. *
  530. * @param $modules
  531. * An array of modules to install.
  532. * @param $reset
  533. * Clear the module info cache.
  534. */
  535. function features_install_modules($modules) {
  536. module_load_include('inc', 'features', 'features.export');
  537. $files = system_rebuild_module_data();
  538. // Build maximal list of dependencies.
  539. $install = array();
  540. foreach ($modules as $name) {
  541. // Parse the dependency string into the module name and version information.
  542. $parsed_name = drupal_parse_dependency($name);
  543. $name = $parsed_name['name'];
  544. if ($file = $files[$name]) {
  545. $install[] = $name;
  546. if (!empty($file->info['dependencies'])) {
  547. $install = array_merge($install, _features_export_maximize_dependencies($file->info['dependencies']));
  548. }
  549. }
  550. }
  551. // Filter out enabled modules.
  552. $enabled = array_filter($install, 'module_exists');
  553. $install = array_diff($install, $enabled);
  554. if (!empty($install)) {
  555. // Make sure the install API is available.
  556. $install = array_unique($install);
  557. include_once DRUPAL_ROOT . '/' . './includes/install.inc';
  558. module_enable($install);
  559. }
  560. }
  561. /**
  562. * Wrapper around features_get_info() that returns an array
  563. * of module info objects that are features.
  564. */
  565. function features_get_features($name = NULL, $reset = FALSE) {
  566. return features_get_info('feature', $name, $reset);
  567. }
  568. /**
  569. * Helper for retrieving info from system table.
  570. */
  571. function features_get_info($type = 'module', $name = NULL, $reset = FALSE) {
  572. static $cache;
  573. if (!isset($cache)) {
  574. $cache = cache_get('features_module_info');
  575. }
  576. if (empty($cache) || $reset) {
  577. $data = array(
  578. 'feature' => array(),
  579. 'module' => array(),
  580. );
  581. $ignored = variable_get('features_ignored_orphans', array());
  582. $files = system_rebuild_module_data();
  583. foreach ($files as $row) {
  584. // Avoid false-reported feature overrides for php = 5.2.4 line in .info file.
  585. if (isset($row->info['php'])) {
  586. unset($row->info['php']);
  587. }
  588. // If module is no longer enabled, remove it from the ignored orphans list.
  589. if (in_array($row->name, $ignored, TRUE) && !$row->status) {
  590. $key = array_search($row->name, $ignored, TRUE);
  591. unset($ignored[$key]);
  592. }
  593. if (!empty($row->info['features'])) {
  594. // Fix css/js paths
  595. if (!empty($row->info['stylesheets'])) {
  596. foreach($row->info['stylesheets'] as $media => $css) {
  597. $row->info['stylesheets'][$media] = array_keys($css);
  598. }
  599. }
  600. if (!empty($row->info['scripts'])) {
  601. $row->info['scripts'] = array_keys($row->info['scripts']);
  602. }
  603. // Rework the features array, to change the vocabulary permission
  604. // features.
  605. foreach ($row->info['features'] as $component => $features) {
  606. if ($component == 'user_permission') {
  607. foreach ($features as $key => $feature) {
  608. // Export vocabulary permissions using the machine name, instead
  609. // of vocabulary id.
  610. _user_features_change_term_permission($feature);
  611. $row->info['features'][$component][$key] = $feature;
  612. }
  613. }
  614. }
  615. $data['feature'][$row->name] = $row;
  616. $data['feature'][$row->name]->components = array_keys($row->info['features']);
  617. if (!empty($row->info['dependencies'])) {
  618. $data['feature'][$row->name]->components[] = 'dependencies';
  619. }
  620. }
  621. $data['module'][$row->name] = $row;
  622. }
  623. // Sort features according to dependencies.
  624. // @see install_profile_modules()
  625. $required = array();
  626. $non_required = array();
  627. $modules = array_keys($data['feature']);
  628. foreach ($modules as $module) {
  629. if ($files[$module]->requires) {
  630. $modules = array_merge($modules, array_keys($files[$module]->requires));
  631. }
  632. }
  633. $modules = array_unique($modules);
  634. foreach ($modules as $module) {
  635. if (!empty($files[$module]->info['features'])) {
  636. if (!empty($files[$module]->info['required'])) {
  637. $required[$module] = $files[$module]->sort;
  638. }
  639. else {
  640. $non_required[$module] = $files[$module]->sort;
  641. }
  642. }
  643. }
  644. arsort($required);
  645. arsort($non_required);
  646. $sorted = array();
  647. foreach ($required + $non_required as $module => $weight) {
  648. $sorted[$module] = $data['feature'][$module];
  649. }
  650. $data['feature'] = $sorted;
  651. variable_set('features_ignored_orphans', $ignored);
  652. cache_set("features_module_info", $data);
  653. $cache = new stdClass();
  654. $cache->data = $data;
  655. }
  656. if (!empty($name)) {
  657. return !empty($cache->data[$type][$name]) ? clone $cache->data[$type][$name] : array();
  658. }
  659. return !empty($cache->data[$type]) ? $cache->data[$type] : array();
  660. }
  661. /**
  662. * Generate an array of feature dependencies that have been orphaned.
  663. */
  664. function features_get_orphans($reset = FALSE) {
  665. static $orphans;
  666. if (!isset($orphans) || $reset) {
  667. module_load_include('inc', 'features', 'features.export');
  668. $orphans = array();
  669. // Build a list of all dependencies for enabled and disabled features.
  670. $dependencies = array('enabled' => array(), 'disabled' => array());
  671. $features = features_get_features();
  672. foreach ($features as $feature) {
  673. $key = module_exists($feature->name) ? 'enabled' : 'disabled';
  674. if (!empty($feature->info['dependencies'])) {
  675. $dependencies[$key] = array_merge($dependencies[$key], _features_export_maximize_dependencies($feature->info['dependencies']));
  676. }
  677. }
  678. $dependencies['enabled'] = array_unique($dependencies['enabled']);
  679. $dependencies['disabled'] = array_unique($dependencies['disabled']);
  680. // Find the list of orphaned modules.
  681. $orphaned = array_diff($dependencies['disabled'], $dependencies['enabled']);
  682. $orphaned = array_intersect($orphaned, module_list(FALSE, FALSE));
  683. $orphaned = array_diff($orphaned, drupal_required_modules());
  684. $orphaned = array_diff($orphaned, array('features'));
  685. // Build final list of modules that can be disabled.
  686. $modules = features_get_modules(NULL, TRUE);
  687. $enabled = module_list();
  688. _module_build_dependencies($modules);
  689. foreach ($orphaned as $module) {
  690. if (!empty($modules[$module]->required_by)) {
  691. foreach ($modules[$module]->required_by as $module_name => $dependency) {
  692. $modules[$module]->required_by[$module_name] = $dependency['name'];
  693. }
  694. // Determine whether any dependents are actually enabled.
  695. $dependents = array_intersect($modules[$module]->required_by, $enabled);
  696. if (empty($dependents)) {
  697. $info = features_get_modules($module);
  698. $orphans[$module] = $info;
  699. }
  700. }
  701. }
  702. }
  703. return $orphans;
  704. }
  705. /**
  706. * Detect potential conflicts between any features that provide
  707. * identical components.
  708. */
  709. function features_get_conflicts($reset = FALSE) {
  710. $conflicts = array();
  711. $component_info = features_get_components();
  712. $map = features_get_component_map(NULL, $reset);
  713. foreach ($map as $type => $components) {
  714. // Only check conflicts for components we know about.
  715. if (isset($component_info[$type])) {
  716. foreach ($components as $component => $modules) {
  717. if (isset($component_info[$type]['duplicates']) && $component_info[$type]['duplicates'] == FEATURES_DUPLICATES_ALLOWED) {
  718. continue;
  719. }
  720. else if (count($modules) > 1) {
  721. foreach ($modules as $module) {
  722. if (!isset($conflicts[$module])) {
  723. $conflicts[$module] = array();
  724. }
  725. foreach ($modules as $m) {
  726. if ($m != $module) {
  727. $conflicts[$module][$m][$type][] = $component;
  728. }
  729. }
  730. }
  731. }
  732. }
  733. }
  734. }
  735. return $conflicts;
  736. }
  737. /**
  738. * Provide a component to feature map.
  739. */
  740. function features_get_component_map($key = NULL, $reset = FALSE) {
  741. static $map;
  742. if (!isset($map) || $reset) {
  743. $map = array();
  744. $features = features_get_features(NULL, $reset);
  745. foreach ($features as $feature) {
  746. foreach ($feature->info['features'] as $type => $components) {
  747. if (!isset($map[$type])) {
  748. $map[$type] = array();
  749. }
  750. foreach ($components as $component) {
  751. $map[$type][$component][] = $feature->name;
  752. }
  753. }
  754. }
  755. }
  756. if (isset($key)) {
  757. return isset($map[$key]) ? $map[$key] : array();
  758. }
  759. return $map;
  760. }
  761. /**
  762. * Simple wrapper returns the status of a module.
  763. */
  764. function features_get_module_status($module) {
  765. if (module_exists($module)) {
  766. return FEATURES_MODULE_ENABLED;
  767. }
  768. else if (features_get_modules($module)) {
  769. return FEATURES_MODULE_DISABLED;
  770. }
  771. else {
  772. return FEATURES_MODULE_MISSING;
  773. }
  774. }
  775. /**
  776. * Menu title callback.
  777. */
  778. function features_get_feature_title($feature) {
  779. return $feature->info['name'];
  780. }
  781. /**
  782. * Menu access callback for whether a user should be able to access
  783. * override actions for a given feature.
  784. */
  785. function features_access_override_actions($feature) {
  786. if (user_access('administer features')) {
  787. static $access = array();
  788. if (!isset($access[$feature->name])) {
  789. // Set a value first. We may get called again from within features_detect_overrides().
  790. $access[$feature->name] = FALSE;
  791. features_include();
  792. module_load_include('inc', 'features', 'features.export');
  793. $access[$feature->name] = in_array(features_get_storage($feature->name), array(FEATURES_OVERRIDDEN, FEATURES_NEEDS_REVIEW)) && user_access('administer features');
  794. }
  795. return $access[$feature->name];
  796. }
  797. return FALSE;
  798. }
  799. /**
  800. * Implements hook_form_alter() for system_modules form().
  801. */
  802. function features_form_system_modules_alter(&$form) {
  803. features_rebuild();
  804. }
  805. /**
  806. * Restore the specified modules to the default state.
  807. */
  808. function _features_restore($op, $items = array()) {
  809. // Set this variable in $conf if having timeout issues during install/rebuild.
  810. if (variable_get('features_restore_time_limit_' . $op, FALSE) !== FALSE) {
  811. drupal_set_time_limit(variable_get('features_restore_time_limit_' . $op, FALSE));
  812. }
  813. module_load_include('inc', 'features', 'features.export');
  814. features_include();
  815. switch ($op) {
  816. case 'revert':
  817. $restore_states = array(FEATURES_OVERRIDDEN, FEATURES_REBUILDABLE, FEATURES_NEEDS_REVIEW);
  818. $restore_hook = 'features_revert';
  819. $log_action = 'Revert';
  820. break;
  821. case 'rebuild':
  822. $restore_states = array(FEATURES_REBUILDABLE);
  823. $restore_hook = 'features_rebuild';
  824. $log_action = 'Rebuild';
  825. break;
  826. case 'disable':
  827. $restore_hook = 'features_disable_feature';
  828. $log_action = 'Disable';
  829. break;
  830. case 'enable':
  831. $restore_hook = 'features_enable_feature';
  832. $log_action = 'Enable';
  833. break;
  834. }
  835. if (empty($items)) {
  836. // Drush may execute a whole chain of commands that may trigger feature
  837. // rebuilding multiple times during a single request. Make sure we do not
  838. // rebuild the same cached list of modules over and over again by setting
  839. // $reset to TRUE.
  840. // Note: this may happen whenever more than one feature will be enabled
  841. // in chain, for example also using features_install_modules().
  842. $states = features_get_component_states(array(), ($op == 'rebuild'), defined('DRUSH_BASE_PATH'));
  843. foreach ($states as $module_name => $components) {
  844. foreach ($components as $component => $state) {
  845. if (in_array($state, $restore_states)) {
  846. $items[$module_name][] = $component;
  847. }
  848. }
  849. }
  850. }
  851. foreach ($items as $module_name => $components) {
  852. foreach ($components as $component) {
  853. // Invoke pre hook
  854. $pre_hook = 'pre_' . $restore_hook;
  855. module_invoke($module_name, $pre_hook, $component);
  856. if (features_hook($component, $restore_hook)) {
  857. // Set a semaphore to prevent other instances of the same script from running concurrently.
  858. watchdog('features', '@actioning @module_name / @component.', array('@action' => $log_action, '@component' => $component, '@module_name' => $module_name));
  859. features_semaphore('set', $component);
  860. features_invoke($component, $restore_hook, $module_name);
  861. // If the script completes, remove the semaphore and set the code signature.
  862. features_semaphore('del', $component);
  863. features_set_signature($module_name, $component);
  864. watchdog('features', '@action completed for @module_name / @component.', array('@action' => $log_action, '@component' => $component, '@module_name' => $module_name));
  865. }
  866. // Invoke post hook
  867. $post_hook = 'post_' . $restore_hook;
  868. module_invoke($module_name, $post_hook, $component);
  869. }
  870. }
  871. }
  872. /**
  873. * Wrapper around _features_restore().
  874. */
  875. function features_revert($revert = array()) {
  876. return _features_restore('revert', $revert);
  877. }
  878. /**
  879. * Wrapper around _features_restore().
  880. */
  881. function features_rebuild($rebuild = array()) {
  882. return _features_restore('rebuild', $rebuild);
  883. }
  884. /**
  885. * Revert a single features module.
  886. *
  887. * @param string $module
  888. * A features module machine name. This module must be a
  889. * features module and enabled.
  890. */
  891. function features_revert_module($module) {
  892. if (($feature = feature_load($module, TRUE)) && module_exists($module)) {
  893. $components = array();
  894. foreach (array_keys($feature->info['features']) as $component) {
  895. if (features_hook($component, 'features_revert')) {
  896. $components[] = $component;
  897. }
  898. }
  899. features_revert(array($module => $components));
  900. }
  901. }
  902. /**
  903. * Utility functions ==================================================
  904. */
  905. /**
  906. * Log a message, environment agnostic.
  907. *
  908. * @param $message
  909. * The message to log.
  910. * @param $severity
  911. * The severity of the message: status, warning or error.
  912. */
  913. function features_log($message, $severity = 'status') {
  914. if (function_exists('drush_verify_cli')) {
  915. $message = strip_tags($message);
  916. if ($severity == 'status') {
  917. $severity = 'ok';
  918. }
  919. elseif ($severity == 'error') {
  920. drush_set_error($message);
  921. return;
  922. }
  923. drush_log($message, $severity);
  924. return;
  925. }
  926. drupal_set_message($message, $severity, FALSE);
  927. }
  928. /**
  929. * Implements hook_hook_info().
  930. */
  931. function features_hook_info() {
  932. $hooks = array(
  933. 'features_api',
  934. 'features_pipe_alter',
  935. 'features_export_alter',
  936. );
  937. return array_fill_keys($hooks, array('group' => 'features'));
  938. }
  939. /**
  940. * Change vocabularies permission, from vocab id to machine name and vice versa.
  941. */
  942. function _user_features_change_term_permission(&$perm, $type = 'vid') {
  943. // Export vocabulary permissions using the machine name, instead of vocabulary
  944. // id.
  945. if (strpos($perm, 'edit terms in ') !== FALSE || strpos($perm, 'delete terms in ') !== FALSE) {
  946. preg_match("/(?<=\040)([^\s]+?)$/", trim($perm), $voc_id);
  947. $vid = $voc_id[0];
  948. if (is_numeric($vid) && $type == 'vid') {
  949. if (function_exists('taxonomy_vocabulary_load')) {
  950. if ($voc = taxonomy_vocabulary_load($vid)) {
  951. $perm = str_replace($vid, $voc->machine_name, $perm);
  952. }
  953. }
  954. }
  955. elseif ($type == 'machine_name') {
  956. if ($voc = taxonomy_vocabulary_machine_name_load($vid)) {
  957. $perm = str_replace($vid, $voc->vid, $perm);
  958. }
  959. }
  960. }
  961. }
  962. /**
  963. * Recursively computes the difference of arrays with additional index check.
  964. *
  965. * This is a version of array_diff_assoc() that supports multidimensional
  966. * arrays.
  967. *
  968. * @param array $array1
  969. * The array to compare from.
  970. * @param array $array2
  971. * The array to compare to.
  972. *
  973. * @return array
  974. * Returns an array containing all the values from array1 that are not present
  975. * in array2.
  976. */
  977. function features_array_diff_assoc_recursive(array $array1, array $array2) {
  978. $difference = array();
  979. foreach ($array1 as $key => $value) {
  980. if (is_array($value)) {
  981. if (!isset($array2[$key]) || !is_array($array2[$key])) {
  982. $difference[$key] = $value;
  983. }
  984. else {
  985. $new_diff = features_array_diff_assoc_recursive($value, $array2[$key]);
  986. if (!empty($new_diff)) {
  987. $difference[$key] = $new_diff;
  988. }
  989. }
  990. }
  991. elseif (!isset($array2[$key]) || $array2[$key] != $value) {
  992. $difference[$key] = $value;
  993. }
  994. }
  995. return $difference;
  996. }
  997. /**
  998. * Returns an array of deprecated components
  999. * Rather than deprecating the component directly, we look for other components
  1000. * that supersedes the component
  1001. * @param $components
  1002. * The array of components (component_info) from features_get_components typically.
  1003. */
  1004. function features_get_deprecated($components = array()) {
  1005. if (empty($components)) {
  1006. $components = features_get_components();
  1007. }
  1008. $deprecated = array();
  1009. foreach ($components as $component => $component_info) {
  1010. if (!empty($component_info['supersedes'])) {
  1011. $deprecated[$component_info['supersedes']] = $component_info['supersedes'];
  1012. }
  1013. }
  1014. return $deprecated;
  1015. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.