You are here

public function BlockManagerForm::viewDetails in Gutenberg 8.2

Same name and namespace in other branches
  1. 8 modules/gutenberg_cloud/src/Form/BlockManagerForm.php \Drupal\gutenberg_cloud\Form\BlockManagerForm::viewDetails()

Ajax callback to display block details in modal.

Parameters

array $form: Form structure.

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

Return value

\Drupal\Core\Ajax\AjaxResponse Modal dialog.

File

modules/gutenberg_cloud/src/Form/BlockManagerForm.php, line 247

Class

BlockManagerForm
Configure Gutenberg Cloud blocks.

Namespace

Drupal\gutenberg_cloud\Form

Code

public function viewDetails(array &$form, FormStateInterface $form_state) {
  $element = $form_state
    ->getTriggeringElement();
  $name = str_replace('details__', '', $element['#name']);
  $block = $this->blockManager
    ->loadRemote($name);
  $rawBlock = $block
    ->getRaw();
  $details = [
    '#theme' => 'gutenberg_cloud__details',
    '#name' => $block
      ->getLabel(),
    '#version' => $block
      ->getVersion(),
    '#description' => $block
      ->getDescription(),
    '#author' => $rawBlock->package->author->name,
    '#author_url' => $rawBlock->package->author->url,
    '#picture' => $block
      ->getAssetUrl('screenshot', $this->blockManager
      ->getCdnUrl()),
    '#tags' => $rawBlock->package->keywords,
  ];
  $details['#attached']['library'][] = 'core/drupal.dialog.ajax';
  $details['#attached']['library'][] = 'gutenberg_cloud/details';
  $response = new AjaxResponse();
  $response
    ->addCommand(new OpenModalDialogCommand($block
    ->getLabel(), $details, [
    'width' => '80%',
  ]));
  return $response;
}