You are here

public function PanelsIPEPageController::getBlockContentForm in Panels 8.4

Same name and namespace in other branches
  1. 8.3 panels_ipe/src/Controller/PanelsIPEPageController.php \Drupal\panels_ipe\Controller\PanelsIPEPageController::getBlockContentForm()

Drupal AJAX compatible route for rendering a Block Content Type's form.

Parameters

string $panels_storage_type: The id of the storage plugin.

string $panels_storage_id: The id within the storage plugin for the requested Panels display.

string $type: The requested Block Type.

string $block_content_uuid: The Block Content Entity UUID, if this is an existing Block.

Return value

\Drupal\Core\Ajax\AjaxResponse

Throws

\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException

1 string reference to 'PanelsIPEPageController::getBlockContentForm'
panels_ipe.routing.yml in panels_ipe/panels_ipe.routing.yml
panels_ipe/panels_ipe.routing.yml

File

panels_ipe/src/Controller/PanelsIPEPageController.php, line 468

Class

PanelsIPEPageController
Contains all JSON endpoints required for Panels IPE + Page Manager.

Namespace

Drupal\panels_ipe\Controller

Code

public function getBlockContentForm($panels_storage_type, $panels_storage_id, $type, $block_content_uuid = NULL) {
  $storage = $this
    ->entityTypeManager()
    ->getStorage('block_content');

  // Create or load a new block of the given type.
  if ($block_content_uuid) {
    $block_list = $storage
      ->loadByProperties([
      'uuid' => $block_content_uuid,
    ]);
    $block = array_shift($block_list);
    $operation = 'update';
  }
  else {
    $block = $storage
      ->create([
      'type' => $type,
    ]);
    $operation = 'create';
  }

  // Check Block Content entity access for the current operation.
  if (!$block
    ->access($operation)) {
    throw new AccessDeniedHttpException();
  }

  // Grab our Block Content Entity form handler, and pass the Panels display
  // variant to it in $form_state.
  $form_state = [
    'panels_display' => $this
      ->loadPanelsDisplay($panels_storage_type, $panels_storage_id),
  ];
  $form = $this
    ->entityFormBuilder()
    ->getForm($block, 'panels_ipe', $form_state);

  // Return the rendered form as a proper Drupal AJAX response.
  $response = new AjaxResponse();
  $command = new AppendCommand('.ipe-block-form', $form);
  $response
    ->addCommand($command);
  return $response;
}