diff --git a/modules/ds_forms/ds_forms.module b/modules/ds_forms/ds_forms.module
index 45e989c..a6996ad 100644
--- a/modules/ds_forms/ds_forms.module
+++ b/modules/ds_forms/ds_forms.module
@@ -73,17 +73,39 @@ function ds_forms_form_field_ui_field_overview_form_alter(&$form, &$form_state)
  * Implements hook_form_alter().
  */
 function ds_forms_form_alter(&$form, &$form_state, $form_id) {
-  if ($ds_form = ds_build_load($form, $form_id)) {
-    if ($layout = ds_get_layout($ds_form->entity_type, $ds_form->bundle, 'form', FALSE)) {
-      // Add the theming function and add the layout as a class.
-      $form['#theme'] = array('ds_forms_custom_form');
-      $class = strtr($layout['layout'], '_', '-');
-      if ((isset($form['#attributes']['class']) && is_array($form['#attributes']['class'])) || !(isset($form['#attributes']['class']))) {
-        $form['#attributes']['class'][] = $class;
+  // One entity
+  if (isset($form['#bundle'])) {
+    if ($ds_form = ds_build_load($form, $form_id)) {
+      if ($layout = ds_get_layout($ds_form->entity_type, $ds_form->bundle, 'form', FALSE)) {
+        // Add the theming function and add the layout as a class.
+        $form['#theme'] = array('ds_forms_custom_form');
+        $class = strtr($layout['layout'], '_', '-');
+        if ((isset($form['#attributes']['class']) && is_array($form['#attributes']['class'])) || !(isset($form['#attributes']['class']))) {
+          $form['#attributes']['class'][] = $class;
+        }
+        elseif (isset($form['#attributes']['class']) && is_string($form['#attributes']['class'])) {
+          $form['#attributes']['class'] .= ' ' . $class . ' ';
+        }
       }
-      elseif (isset($form['#attributes']['class']) && is_string($form['#attributes']['class'])) {
-        $form['#attributes']['class'] .= ' ' . $class . ' ';
+    }
+  }
+  // Nested entities
+  else {
+    foreach (element_children($form) as $key) {
+      if ($ds_form = ds_build_load($form[$key], $form_id)) {
+        if ($layout = ds_get_layout($ds_form->entity_type, $ds_form->bundle, 'form', FALSE)) {
+          // Add the theming function and add the layout as a class.
+          $form[$key]['#theme'] = array('ds_forms_custom_form');
+          $class = strtr($layout['layout'], '_', '-');
+          if ((isset($form[$key]['#attributes']['class']) && is_array($form[$key]['#attributes']['class'])) || !(isset($form[$key]['#attributes']['class']))) {
+            $form[$key]['#attributes']['class'][] = $class;
+          }
+          elseif (isset($form['#attributes']['class']) && is_string($form['#attributes']['class'])) {
+            $form[$key]['#attributes']['class'] .= ' ' . $class . ' ';
+          }
+        }
       }
+      $form[$key]['#form_id'] = $form_id;
     }
   }
 }
