Hide specific features

Public

This snippet allows for hiding of specific features, and their associated package group from the features admin form, located at the /admin/structure/features path.

</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_form_FORM_ID_alter().
  3.  * This function will hide the specified features from the features list,
  4.  * including their associated package group, if that package becomes empty
  5.  * after hiding features.
  6.  */
  7. function MY_MODULE_form_features_admin_form_alter(&$form, &$form_state) {
  8. $features_to_hide = array(
  9. // specify features machine names here, for example:
  10. 'date_migrate_example',
  11. 'feeds_import',
  12. 'feeds_news',
  13. );
  14.  
  15. // Nothing below this line need be changed
  16.  
  17.  
  18. foreach ($form as $package => $data) {
  19. if (is_array($data) && isset($data['#group']) && $data['#group'] == 'packages') {
  20. foreach($features_to_hide as $feature) {
  21. unset($form['#features'][$feature]);
  22. if (isset($form[$package]['status'][$feature])) {
  23. unset(
  24. $form[$package]['status'][$feature],
  25. $form[$package]['sign'][$feature],
  26. $form[$package]['state'][$feature],
  27. $form[$package]['actions'][$feature]
  28. );
  29. }
  30. }
  31. if (empty($form[$package]['actions'])) {
  32. unset($form[$package]);
  33. }
  34. }
  35. }
  36. }