You are here

public function QuickEditController::entitySave in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/quickedit/src/QuickEditController.php \Drupal\quickedit\QuickEditController::entitySave()
  2. 9 core/modules/quickedit/src/QuickEditController.php \Drupal\quickedit\QuickEditController::entitySave()

Saves an entity into the database, from PrivateTempStore.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity being edited.

Return value

\Drupal\Core\Ajax\AjaxResponse The Ajax response.

1 string reference to 'QuickEditController::entitySave'
quickedit.routing.yml in core/modules/quickedit/quickedit.routing.yml
core/modules/quickedit/quickedit.routing.yml

File

core/modules/quickedit/src/QuickEditController.php, line 339

Class

QuickEditController
Returns responses for Quick Edit module routes.

Namespace

Drupal\quickedit

Code

public function entitySave(EntityInterface $entity) {
  self::checkCsrf(\Drupal::request(), \Drupal::currentUser());

  // Take the entity from PrivateTempStore and save in entity storage.
  // fieldForm() ensures that the PrivateTempStore copy exists ahead.
  $tempstore = $this->tempStoreFactory
    ->get('quickedit');
  $tempstore
    ->get($entity
    ->uuid())
    ->save();
  $tempstore
    ->delete($entity
    ->uuid());

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

  // Respond to client that the entity was saved properly.
  $response = new AjaxResponse();
  $response
    ->addCommand(new EntitySavedCommand($output));
  return $response;
}