You are here

protected function PanelsIPEBlockPluginForm::getBlockInstance in Panels 8.3

Same name and namespace in other branches
  1. 8.4 panels_ipe/src/Form/PanelsIPEBlockPluginForm.php \Drupal\panels_ipe\Form\PanelsIPEBlockPluginForm::getBlockInstance()

Loads or creates a Block Plugin instance suitable for rendering or testing.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\Core\Block\BlockPluginInterface The Block Plugin instance.

3 calls to PanelsIPEBlockPluginForm::getBlockInstance()
PanelsIPEBlockPluginForm::submitForm in panels_ipe/src/Form/PanelsIPEBlockPluginForm.php
Form submission handler.
PanelsIPEBlockPluginForm::submitPreview in panels_ipe/src/Form/PanelsIPEBlockPluginForm.php
Previews our current Block configuration.
PanelsIPEBlockPluginForm::validateForm in panels_ipe/src/Form/PanelsIPEBlockPluginForm.php
Form validation handler.

File

panels_ipe/src/Form/PanelsIPEBlockPluginForm.php, line 380

Class

PanelsIPEBlockPluginForm
Provides a form for adding a block plugin temporarily using AJAX.

Namespace

Drupal\panels_ipe\Form

Code

protected function getBlockInstance(FormStateInterface $form_state) {

  // If a UUID is provided, the Block should already exist.
  if ($uuid = $form_state
    ->getValue('uuid')) {

    // If a temporary configuration for this variant exists, use it.
    $temp_store_key = $this->panelsDisplay
      ->id();
    if ($variant_config = $this->tempStore
      ->get($temp_store_key)) {
      $this->panelsDisplay
        ->setConfiguration($variant_config);
    }

    // Load the existing Block instance.
    $block_instance = $this->panelsDisplay
      ->getBlock($uuid);
  }
  else {

    // Create an instance of this Block plugin.

    /** @var \Drupal\Core\Block\BlockBase $block_instance */
    $block_instance = $this->blockManager
      ->createInstance($form_state
      ->getValue('plugin_id'));
  }
  return $block_instance;
}