You are here

public function AjaxFormEntityController::ajaxForm in Ajax form entity 8

Sends back a form entity to edit any content entity.

1 string reference to 'AjaxFormEntityController::ajaxForm'
ajax_form_entity.routing.yml in ./ajax_form_entity.routing.yml
ajax_form_entity.routing.yml

File

src/Controller/AjaxFormEntityController.php, line 54

Class

AjaxFormEntityController
Class AjaxFormEntityController.

Namespace

Drupal\ajax_form_entity\Controller

Code

public function ajaxForm($entity_type, $id, $popin, $view_mode) {

  // Get the entity and generate the form.
  $entity = $this->entityTypeManager
    ->getStorage($entity_type)
    ->load($id);
  $form = $this->entityFormBuilder
    ->getForm($entity);

  // If popin, return directly, else return an AJAX callback.
  if ($popin) {
    return $form;
  }
  else {
    $response = new AjaxResponse();
    $selector = '.ajax-form-entity-view-' . $entity_type . '-' . $id;
    $response
      ->addCommand(new ReplaceCommand($selector, $form));
    return $response;
  }
}