You are here

public function FieldInheritanceController::ajaxCreationForm in Field Inheritance 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/FieldInheritanceController.php \Drupal\field_inheritance\Controller\FieldInheritanceController::ajaxCreationForm()

Gets the creation form in a modal.

Parameters

string $entity_type: The entity type.

string $entity_bundle: The entity bundle.

Return value

\Drupal\Core\Ajax\AjaxResponse Returns an ajax response.

1 string reference to 'FieldInheritanceController::ajaxCreationForm'
field_inheritance.routing.yml in ./field_inheritance.routing.yml
field_inheritance.routing.yml

File

src/Controller/FieldInheritanceController.php, line 27

Class

FieldInheritanceController
The FieldInheritanceController class.

Namespace

Drupal\field_inheritance\Controller

Code

public function ajaxCreationForm($entity_type = NULL, $entity_bundle = NULL) {
  $inheritance_entity = $this
    ->entityTypeManager()
    ->getStorage('field_inheritance')
    ->create();
  $inheritance_entity
    ->setDestinationEntityType($entity_type);
  $inheritance_entity
    ->setDestinationEntityBundle($entity_bundle);
  $form_object = $this
    ->entityTypeManager()
    ->getFormObject('field_inheritance', 'ajax');
  $form_object
    ->setEntity($inheritance_entity);
  $form_state = (new FormState())
    ->setFormObject($form_object)
    ->disableRedirect();
  $modal_form = $this
    ->formBuilder()
    ->buildForm($form_object, $form_state);
  $modal_form['#attached']['library'][] = 'core/drupal.dialog.ajax';
  $response = new AjaxResponse();
  $response
    ->addCommand(new OpenModalDialogCommand('Add Field Inheritance', $modal_form, [
    'width' => '800',
  ]));
  return $response;
}