You are here

public function JeditableAjax::jeditableAjaxSave in jEditable inline content editing 8

Saves latest changed value.

Return value

\Symfony\Component\HttpFoundation\Response Return Updated value.

1 string reference to 'JeditableAjax::jeditableAjaxSave'
jeditable.routing.yml in ./jeditable.routing.yml
jeditable.routing.yml

File

src/Controller/JeditableAjax.php, line 24

Class

JeditableAjax
Class JeditableAjax.

Namespace

Drupal\jeditable\Controller

Code

public function jeditableAjaxSave() {
  $array = explode('-', $_POST['id']);

  // Fieldtype and $delta can used when expanding the scope of the module.
  list($type, $id, $field_name, $field_type, $delta) = $array;
  $value = Html::escape($_POST['value']);
  $storage = $this
    ->entityTypeManager()
    ->getStorage($type);
  if ($storage instanceof EntityStorageInterface) {
    $entity = $storage
      ->load($id);
    if ($entity instanceof EntityInterface) {
      $entity->{$field_name}->value = $value;
      $entity
        ->save();
      return new Response($value);
    }
  }

  // The entity could not be loaded, return the appropriate code.
  return new Response($value, 400);
}