You are here

public function CommerceDiscountUIController::entityFormSubmitBuildEntity in Commerce Discount 7

Entity submit builder invoked via entity_ui_form_submit_build_entity().

Extracts the form values and updates the entity.

The provided implementation makes use of the helper function entity_form_submit_build_entity() provided by core, which already invokes the field API attacher for fieldable entities.

Return value

object The updated entity.

Overrides EntityDefaultUIController::entityFormSubmitBuildEntity

See also

entity_ui_form_submit_build_entity()

File

includes/commerce_discount.admin.inc, line 16
Commerce discount editing UI.

Class

CommerceDiscountUIController
Class CommerceDiscountUIController.

Code

public function entityFormSubmitBuildEntity($form, &$form_state) {

  // We cannot use entity_form_submit_build_entity() any more.
  $entity = $form_state['commerce_discount'];

  // Extract form values.
  form_state_values_clean($form_state);
  foreach ($form_state['values'] as $key => $value) {
    if ($key != 'commerce_discount_fields') {
      $entity->{$key} = $value;
    }
    else {
      $discount_offer = $value['commerce_discount_offer'][LANGUAGE_NONE]['form'];
      unset($discount_offer['actions']);
      $entity->commerce_discount_offer['commerce_discount_fields'] = $discount_offer;
    }
  }

  // Invoke all specified builders for copying values to entity properties.
  // @see entity_form_submit_build_entity()
  if (isset($form['#entity_builders'])) {
    foreach ($form['#entity_builders'] as $function) {
      $function('commerce_discount', $entity, $form, $form_state);
    }
  }
  field_attach_submit('commerce_discount', $entity, $form['commerce_discount_fields'], $form_state);
  return $entity;
}