ajax_form_entity.callback.inc in Ajax form entity 7.x
File
ajax_form_entity.callback.inc
View source
<?php
function ajax_form_entity_entity_edit_callback($type = 'ajax') {
$entity_type = arg(3);
$entity_id = arg(4);
$special_id = arg(5);
$ids[] = $entity_id;
$entity = entity_load($entity_type, $ids);
if (entity_access('update', $entity_type, $entity[$entity_id])) {
if ($type == 'ajax') {
$form_state['build_info']['args'][] = $entity;
$form['#prefix'] = '<div id="form-closing-wrapper-' . $special_id . '">';
$form['#suffix'] = '</div>';
$form = _ajax_form_entity_build_entity_forms($entity_type, array(), array(), $entity);
$form['#prefix'] .= l(t('Close'), 'ajax-form-entity-cancel/nojs/' . $special_id, array(
'attributes' => array(
'class' => array(
'use-ajax button-cancel',
),
),
));
$render_form = drupal_render($form);
$commands = array();
$commands[] = ajax_command_css('#ajax-entity-form-' . $special_id, array(
'display' => 'none',
));
$commands[] = ajax_command_append('#ajax-entity-form-wrapper-' . $special_id, $render_form);
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
ajax_deliver($page);
}
else {
}
}
}
function ajax_form_entity_entity_delete_callback($type = 'ajax') {
$entity_type = arg(3);
$entity_id = arg(4);
$special_id = arg(5);
$ids[] = $entity_id;
$entity = entity_load($entity_type, $ids);
if (entity_access('delete', $entity_type, $entity[$entity_id])) {
if ($type == 'ajax') {
$vars['content'] = 'Deleted';
$message = theme('ajax_form_entity_deleted', $vars);
if ($entity_type == 'field_collection_item') {
$entity[$entity_id]
->delete();
}
else {
entity_delete($entity_type, $entity_id);
}
$commands[] = ajax_command_replace('#ajax-entity-form-' . $special_id, $message . theme('status_messages'));
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
ajax_deliver($page);
}
else {
}
}
}