You are here

function bean_form_submit in Bean (for Drupal 7) 7

Submit function for bean form

1 call to bean_form_submit()
BeanInlineEntityFormController::entityFormSubmit in includes/bean.inline_entity_form.inc
Overrides EntityInlineEntityFormController::entityFormSubmit().
1 string reference to 'bean_form_submit'
bean_form in includes/bean.pages.inc
Bean form

File

includes/bean.pages.inc, line 383
Bean Functions

Code

function bean_form_submit($form, &$form_state) {
  $bean = bean_form_submit_build_bean($form, $form_state);
  $bean
    ->setValues($form_state['values']);

  // Avoid dataloss.
  if (empty($form_state['values']['is_new_revision'])) {
    $bean->default_revision = TRUE;
  }
  $insert = $bean
    ->internalIdentifier();
  field_attach_submit('bean', $bean, $form, $form_state);
  $bean
    ->save();
  $form_state['values']['bean'] = $bean;
  $watchdog_args = array(
    '@type' => $bean->type,
    '%title' => $bean
      ->label(),
  );
  $t_args = array(
    '@type' => $bean
      ->typeName(),
    '%title' => $bean
      ->label(),
  );
  if (!$insert) {
    watchdog('bean', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $bean
      ->viewURL());
    drupal_set_message(t('@type %title has been created.', $t_args));
  }
  else {
    watchdog('bean', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $bean
      ->viewURL());
    drupal_set_message(t('@type %title has been updated.', $t_args));
  }
  if ($bean
    ->identifier()) {
    $form_state['redirect'] = $bean
      ->viewURL();
  }
  else {

    // In the unlikely case something went wrong on save, the bean will be
    // rebuilt and bean form redisplayed the same way as in preview.
    drupal_set_message(t('The block could not be saved.'), 'error');
    $form_state['rebuild'] = TRUE;
  }
}