You are here

function slickgrid_callback_add in Slickgrid 7.2

Same name and namespace in other branches
  1. 7 includes/slickgrid.callbacks.inc \slickgrid_callback_add()

Callback function - add an entity

1 string reference to 'slickgrid_callback_add'
slickgrid_menu in ./slickgrid.module
Implements hook_menu().

File

includes/slickgrid.callbacks.inc, line 48

Code

function slickgrid_callback_add($entity_type, $bundle_type) {
  global $user;
  $entity_info = entity_get_info($entity_type);
  $args = array_slice(func_get_args(), 2);
  ctools_include('modal');
  ctools_include('ajax');
  $form_callback_func = $entity_info['form callback'];
  $entity = NULL;
  if (function_exists($entity_info['creation callback'])) {
    $entity = call_user_func($entity_info['creation callback'], array(
      'type' => $bundle_type,
      'name' => $user->name,
    ), $entity_type);
    $form = $form_callback_func($entity);
  }
  else {
    $form = $form_callback_func();
  }
  $form_state = $_POST + array(
    'title' => t('Add @bundle_label', array(
      '@bundle_label' => strtolower($entity_info['bundles'][$bundle_type]['label']),
    )),
  );
  if (isset($form['#validated']) && !form_get_errors()) {
    $output = array();
    $output[] = ctools_modal_command_dismiss();
    $result = array();
    $result = module_invoke_all('slickgrid_add_entity', $entity_type, $bundle_type, $args, $entity);
    slickgrid_callback_add_messages($result);
    $output[] = array(
      'command' => 'slickgrid',
      'response' => array(
        'result' => $result,
      ),
    );
  }
  else {
    $output = ctools_modal_form_render($form_state, $form);
  }
  print ajax_render($output);
  exit;
}