function bean_services_create in Bean (for Drupal 7) 7
Adds a new bean to a node and returns the bid.
Parameters
$bean Bean: An object as would be returned from bean_load().
Return value
Unique identifier for the bean (bid) or errors if there was a problem.
1 string reference to 'bean_services_create'
- bean_services_resources in ./
bean.services.inc - Implements hook_services_resources().
File
- ./
bean.services.inc, line 137 - Contains callbacks for service resource manipulation.
Code
function bean_services_create($bean) {
if (empty($bean['type'])) {
return services_error(t('A type must be provided.'));
}
// Include the bean_form.
module_load_include('inc', 'bean', 'includes/bean.pages');
$bean_new = bean_create($bean);
// Setup form_state.
$form_state = array();
$form_state['values'] = $bean;
$form_state['values']['op'] = t('Save');
$form_state['build_info']['args'] = array(
&$bean_new,
);
$ret = drupal_form_submit('bean_form', $form_state);
// Error if needed.
if ($errors = form_get_errors()) {
return services_error(implode(" ", $errors), 406, array(
'form_errors' => $errors,
));
}
$bean = $form_state['bean'];
return array(
'bid' => $bean->bid,
'uri' => services_resource_uri(array(
'bean',
$bean->bid,
)),
);
}