You are here

function bean_services_update in Bean (for Drupal 7) 7

Updates a bean and returns the bid.

Parameters

$bid: Unique identifier for this bean.

$bean Bean: An object as would be returned from bean_load().

Return value

Unique identifier for the bean (bid) or FALSE if there was a problem.

1 string reference to 'bean_services_update'
bean_services_resources in ./bean.services.inc
Implements hook_services_resources().

File

./bean.services.inc, line 178
Contains callbacks for service resource manipulation.

Code

function bean_services_update($bid, $bean) {

  // Include the bean_form.
  module_load_include('inc', 'bean', 'includes/bean.pages');
  $bean['bid'] = $bid;
  $old_bean = bean_load($bid);
  if (empty($old_bean)) {
    return services_error(t('Bean @bid not found.', array(
      '@bid' => $bid,
    )), 404);
  }

  // Setup form_state.
  $form_state = array();
  $form_state['values'] = $bean;
  $form_state['values']['op'] = t('Save');
  $form_state['build_info']['args'] = array(
    &$old_bean,
  );
  drupal_form_submit('bean_form', $form_state);
  if ($errors = form_get_errors()) {
    return services_error(implode(" ", $errors), 406, array(
      'form_errors' => $errors,
    ));
  }
  return $bid;
}