/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $block_instance = $this->getBlockInstance($form_state);
     // Submit the block configuration form.
     $block_form_state = (new FormState())->setValues($form_state->getValue('settings'));
     $block_instance->submitConfigurationForm($form, $block_form_state);
     // Update the original form values.
     $form_state->setValue('settings', $block_form_state->getValues());
     // 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);
     }
     // Set the block region appropriately.
     $block_config = $block_instance->getConfiguration();
     $block_config['region'] = $form_state->getValue(array('settings', 'region'));
     // Determine if we need to update or add this block.
     if ($uuid = $form_state->getValue('uuid')) {
         $this->panelsDisplay->updateBlock($uuid, $block_config);
     } else {
         $uuid = $this->panelsDisplay->addBlock($block_config);
     }
     // Set the tempstore value.
     $this->tempStore->set($this->panelsDisplay->id(), $this->panelsDisplay->getConfiguration());
     // Assemble data required for our App.
     $build = $this->buildBlockInstance($block_instance);
     $form['build'] = $build;
     // Add our data attribute for the Backbone app.
     $build['#attributes']['data-block-id'] = $uuid;
     $block_model = ['uuid' => $uuid, 'label' => $block_instance->label(), 'id' => $block_instance->getPluginId(), 'region' => $block_config['region'], 'html' => $this->renderer->render($build)];
     // Add Block metadata and HTML as a drupalSetting.
     $form['#attached']['drupalSettings']['panels_ipe']['updated_block'] = $block_model;
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Return early if there are any errors.
     if ($form_state->hasAnyErrors()) {
         return $form;
     }
     $block_instance = $this->getBlockInstance($form_state);
     // Submit the block configuration form.
     $this->submitBlock($block_instance, $form, $form_state);
     // 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);
     }
     // Set the block region appropriately.
     $block_config = $block_instance->getConfiguration();
     $block_config['region'] = $form_state->getValue(array('settings', 'region'));
     // Determine if we need to update or add this block.
     if ($uuid = $form_state->getValue('uuid')) {
         $this->panelsDisplay->updateBlock($uuid, $block_config);
     } else {
         $uuid = $this->panelsDisplay->addBlock($block_config);
     }
     // Set the tempstore value.
     $this->tempStore->set($this->panelsDisplay->id(), $this->panelsDisplay->getConfiguration());
     // Assemble data required for our App.
     $build = $this->buildBlockInstance($block_instance);
     // Bubble block attributes up if possible. This allows modules like
     // Quickedit to function.
     // See \Drupal\block\BlockViewBuilder::preRender() for reference.
     if ($build['content'] !== NULL && !Element::isEmpty($build['content'])) {
         foreach (['#attributes', '#contextual_links'] as $property) {
             if (isset($build['content'][$property])) {
                 $build[$property] += $build['content'][$property];
                 unset($build['content'][$property]);
             }
         }
     }
     // Add our data attribute for the Backbone app.
     $build['#attributes']['data-block-id'] = $uuid;
     $block_model = ['uuid' => $uuid, 'label' => $block_instance->label(), 'id' => $block_instance->getPluginId(), 'region' => $block_config['region'], 'html' => $this->renderer->render($build)];
     $form['build'] = $build;
     // Add Block metadata and HTML as a drupalSetting.
     $form['#attached']['drupalSettings']['panels_ipe']['updated_block'] = $block_model;
     return $form;
 }