diff --git a/includes/entity.inline_entity_form.inc b/includes/entity.inline_entity_form.inc index 7b3891d..e4d0cc2 100644 --- a/includes/entity.inline_entity_form.inc +++ b/includes/entity.inline_entity_form.inc @@ -144,6 +144,7 @@ class EntityInlineEntityFormController { $defaults['allow_existing'] = FALSE; $defaults['match_operator'] = 'CONTAINS'; $defaults['delete_references'] = FALSE; + $defaults['multi_edit'] = FALSE; $labels = $this->defaultLabels(); $defaults['override_labels'] = FALSE; $defaults['label_singular'] = $labels['singular']; @@ -194,6 +195,13 @@ class EntityInlineEntityFormController { $form['match_operator']['#access'] = FALSE; } + $form['multi_edit'] = array( + '#type' => 'checkbox', + '#title' => t('Multi-edit?'), + '#default_value' => $this->settings['multi_edit'], + '#description' => t('Automatically show the edit forms for all objects.'), + ); + $form['delete_references'] = array( '#type' => 'checkbox', '#title' => t('Delete referenced @label when the parent entity is deleted.', array('@label' => $labels['plural'])), diff --git a/inline_entity_form.module b/inline_entity_form.module index 70935fb..9ba333d 100644 --- a/inline_entity_form.module +++ b/inline_entity_form.module @@ -547,6 +547,11 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins $element['entities']['#table_fields'] = $fields; foreach ($form_state['inline_entity_form'][$ief_id]['entities'] as $key => $value) { + // Optionally auto-load the edit forms. + if ($controller->getSetting('multi_edit') && (!isset($value['form']) || $value['form'] != 'remove')) { + $value['form'] = 'edit'; + } + // Data used by theme_inline_entity_form_entity_table(). $element['entities'][$key]['#entity'] = $entity = $value['entity']; $element['entities'][$key]['#needs_save'] = $value['needs_save']; @@ -557,8 +562,10 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins // First check to see if this entity should be displayed as a form. if (!empty($value['form'])) { $element['entities'][$key]['delta'] = array( - '#type' => 'value', - '#value' => $value['weight'], + '#type' => 'weight', + '#delta' => 50, + '#default_value' => $value['weight'], + '#attributes' => array('class' => array('ief-entity-delta')), ); $element['entities'][$key]['form'] = array( '#type' => 'container', @@ -580,9 +587,44 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins // Prepare data for the form callbacks. $form = &$element['entities'][$key]['form']; + $row['delta'] = array( + '#type' => 'weight', + '#delta' => 50, + '#default_value' => $value['weight'], + '#attributes' => array('class' => array('ief-entity-delta')), + ); + // Add the appropriate form. if ($value['form'] == 'edit') { $form += inline_entity_form_entity_form($controller, $form, $form_state); + + // When the multiedit option is enabled, replace the 'cancel' button + // with a 'remove' button. + if ($controller->getSetting('multi_edit')) { + unset($form['actions']['ief_' . $form['#op'] . '_cancel']); + $remove_form = inline_entity_form_remove_form($controller, $form, $form_state); + // If 'allow_existing' is on, the default removal operation is unlink + // and the access check for deleting happens inside the controller + // removeForm() method. + if (entity_access('delete', $controller->entityType(), $entity)) { + $form['actions']['ief_entity_remove'] = array( + '#type' => 'submit', + '#value' => t('Remove'), + '#name' => 'ief-' . $ief_id . '-entity-remove-' . $key, + '#limit_validation_errors' => array(), + '#ajax' => array( + 'callback' => 'inline_entity_form_get_element', + 'wrapper' => $wrapper, + ), + '#submit' => array('inline_entity_form_open_row_form'), + '#ief_row_delta' => $key, + '#ief_row_form' => 'remove', + ); + } + + // Allow the button group to be themed. + $form['actions']['#attributes']['class'][] = 'form-actions'; + } } elseif ($value['form'] == 'remove') { $form += inline_entity_form_remove_form($controller, $form, $form_state); @@ -1597,19 +1639,11 @@ function theme_inline_entity_form_entity_table($variables) { $fields = $form['#table_fields']; // Sort the fields by weight. uasort($fields, 'drupal_sort_weight'); - // If one of the rows is in form context, disable tabledrag. - $has_tabledrag = TRUE; - foreach (element_children($form) as $key) { - if (!empty($form[$key]['form'])) { - $has_tabledrag = FALSE; - } - } $header = array(); - if ($has_tabledrag) { - $header[] = array('data' => '', 'class' => array('ief-tabledrag-header')); - $header[] = array('data' => t('Sort order'), 'class' => array('ief-sort-order-header')); - } + $header[] = array('data' => '', 'class' => array('ief-tabledrag-header')); + $header[] = array('data' => t('Sort order'), 'class' => array('ief-sort-order-header')); + // Add header columns for each field. $first = TRUE; foreach ($fields as $field_name => $field) { @@ -1638,11 +1672,10 @@ function theme_inline_entity_form_entity_table($variables) { $row_classes = array('ief-row-entity'); $cells = array(); - if ($has_tabledrag) { - $cells[] = array('data' => '', 'class' => array('ief-tabledrag-handle')); - $cells[] = drupal_render($form[$key]['delta']); - $row_classes[] = 'draggable'; - } + $cells[] = array('data' => '', 'class' => array('ief-tabledrag-handle')); + $cells[] = drupal_render($form[$key]['delta']); + $row_classes[] = 'draggable'; + // Add a special class to rows that have a form underneath, to allow // for additional styling. if (!empty($form[$key]['form'])) { @@ -1687,24 +1720,25 @@ function theme_inline_entity_form_entity_table($variables) { } // Add the buttons belonging to the "Operations" column. $cells[] = drupal_render($form[$key]['actions']); - // Create the row. - $rows[] = array('data' => $cells, 'class' => $row_classes); - // If the current entity array specifies a form, output it in the next row. - if (!empty($form[$key]['form'])) { + // No form, so output the normal row. + if (empty($form[$key]['form'])) { + // Create the row. + $rows[] = array('data' => $cells, 'class' => $row_classes); + } + // Output the form as a table row. + else { $row = array( array('data' => drupal_render($form[$key]['form']), 'colspan' => count($fields) + 1), ); - $rows[] = array('data' => $row, 'class' => array('ief-row-form'), 'no_striping' => TRUE); + $rows[] = array('data' => $row, 'class' => $row_classes + array('ief-row-form'), 'no_striping' => TRUE); } } if (!empty($rows)) { $id = 'ief-entity-table-' . $form['#id']; - if ($has_tabledrag) { - // Add the tabledrag JavaScript. - drupal_add_tabledrag($id, 'order', 'sibling', 'ief-entity-delta'); - } + // Add the tabledrag JavaScript. + drupal_add_tabledrag($id, 'order', 'sibling', 'ief-entity-delta'); // Return the themed table. $table_attributes = array(