You are here

function quickedit_entity_save in Quick Edit 7

Page callback: Saves an entity into the database, from TempStore.

Parameters

$entity_type: The type of the entity being saved.

$entity_id: The ID of the entity being saved.

Return value

The Ajax response.

See also

Drupal 8's QuickEditController::entitySave()

1 string reference to 'quickedit_entity_save'
quickedit_menu in ./quickedit.module
Implements hook_menu().

File

includes/pages.inc, line 316
AJAX endpoint to retrieve & save subforms for fields and re-render fields.

Code

function quickedit_entity_save($entity_type, $entity_id) {

  // Ensure the user is allowed to edit this entity.
  if (!entity_access('update', $entity_type, entity_load_single($entity_type, $entity_id))) {
    return MENU_ACCESS_DENIED;
  }

  // Take the entity from TempStore and save in entity storage. fieldForm()
  // ensures that the TempStore copy exists ahead.
  ctools_include('object-cache');
  $tempstore_id = _quickedit_entity_tempstore_id($entity_type, $entity_id);
  $entity = ctools_object_cache_get('quickedit', $tempstore_id);
  ctools_object_cache_clear('quickedit', $tempstore_id);
  entity_save($entity_type, $entity);

  // Return information about the entity that allows a front end application
  // to identify it.
  $output = array(
    'entity_type' => $entity_type,
    'entity_id' => $entity_id,
  );

  // Respond to client that the entity was saved properly.
  $commands = array();
  $commands[] = array(
    'command' => 'quickeditEntitySaved',
    'data' => $output,
  );
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}