From 166000045841ef42d12b1bdf5c539e06ba79b7bc Mon Sep 17 00:00:00 2001
From: Tim Holt <hisboyelroymusic@gmail.com>
Date: Thu, 17 Apr 2014 08:48:18 -0500
Subject: adding admin section to allow you to choose entity types
 to auto-add

---
 modules/deploy_auto_plan/deploy_auto_plan.module | 52 +++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/modules/deploy_auto_plan/deploy_auto_plan.module b/modules/deploy_auto_plan/deploy_auto_plan.module
index 8d47aca..b6d894f 100644
--- a/modules/deploy_auto_plan/deploy_auto_plan.module
+++ b/modules/deploy_auto_plan/deploy_auto_plan.module
@@ -84,6 +84,18 @@ function deploy_auto_plan_settings($form, $form_state) {
     '#default_value' => variable_get('deploy_auto_plan_name', NULL),
   );

+  $form['entity_type_text'] = array(
+    '#markup' => t('Select which types of entities will be automatically added to the plan.'),
+  );
+
+  $form['deploy_auto_plan_entity_types'] = array(
+    '#type' => 'select',
+    '#multiple' => TRUE,
+    '#title' => 'Entity Types',
+    '#options' => _deploy_auto_plan_entity_types(),
+    '#default_value' => variable_get('deploy_auto_plan_entity_types', _deploy_auto_plan_entity_types_defaults()),
+  );
+
   return system_settings_form($form);
 }

@@ -107,10 +119,16 @@ function _deploy_auto_plan_entity_save($entity, $type) {
     return;
   }

+  $allowed_entity_types = variable_get('deploy_auto_plan_entity_types', _deploy_auto_plan_entity_types_defaults());
+  if (!isset($allowed_entity_types[$type])) {
+    // only include entities whose types are selected in the admin
+    return;
+  }
+
   deploy_manager_add_to_plan($plan_name, $type, $entity);
 }

- /**
+/**
  * Fetches a list of deployment plans.
  *
  * @return array
@@ -127,3 +145,35 @@ function _deploy_auto_plan_plans_list() {

   return $options;
 }
+
+/**
+ * Fetches a list of formatted entity types.
+ *
+ * @return array
+ *    The list of all entity types in the site.
+ *    Returns 'name' => 'label'.
+ */
+
+function _deploy_auto_plan_entity_types() {
+  $entity_types = entity_get_info();
+  $types = array();
+  foreach ($entity_types as $entity_type => $attributes) {
+    $types[$entity_type] = $attributes['label'];
+  }
+  return $types;
+}
+
+/**
+ * Fetches default values for the deploy_auto_plan_entity_types variable.
+ *
+ * @return array
+ *    The default value which is all entity types.
+ */
+function _deploy_auto_plan_entity_types_defaults() {
+  $entity_types = _deploy_auto_plan_entity_types();
+  $default_values = array();
+  foreach ($entity_types as $entity_type => $entity_label) {
+    $default_values[$entity_type] = $entity_type;
+  }
+  return $default_values;
+}
--
1.8.5.2

