/**
  * Builds a form that configure an existing or new layout for the IPE.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param string $layout_id
  *   The requested Layout ID.
  * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
  *   The current PageVariant ID.
  *
  * @return array
  *   The form structure.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $layout_id = NULL, PanelsDisplayVariant $panels_display = NULL)
 {
     // We require these default arguments.
     if (!$layout_id || !$panels_display) {
         return FALSE;
     }
     // Save the panels display for later.
     $this->panelsDisplay = $panels_display;
     // Check if this is the current layout, and if not create an instance.
     $layout = $this->panelsDisplay->getLayout();
     $current = $layout->getPluginId() == $layout_id;
     if (!$current) {
         // Create a new layout instance.
         $layout = $this->layoutManager->createInstance($layout_id, []);
     }
     // Save the layout for future use.
     $this->layout = $layout;
     $form['settings'] = $layout->buildConfigurationForm([], $form_state);
     $form['settings']['#tree'] = TRUE;
     // If the form is empty, inform the user.
     if (empty(Element::getVisibleChildren($form['settings']))) {
         $form['settings'][] = ['#markup' => $this->t('<h5>This layout does not provide any configuration.</h5>')];
     }
     // Add an add button, which is only used by our App.
     $form['submit'] = ['#type' => 'button', '#value' => $current ? $this->t('Update') : $this->t('Change Layout'), '#ajax' => ['callback' => '::submitForm', 'wrapper' => 'panels-ipe-layout-form-wrapper', 'method' => 'replace', 'progress' => ['type' => 'throbber', 'message' => '']]];
     return $form;
 }
 /**
  * @covers ::getLayout
  */
 public function testGetLayout()
 {
     $this->assertSame($this->layout->reveal(), $this->variant->getLayout());
 }
 /**
  * {@inheritdoc}
  */
 public function build(PanelsDisplayVariant $panels_display)
 {
     $regions = $panels_display->getRegionAssignments();
     $contexts = $panels_display->getContexts();
     $layout = $panels_display->getLayout();
     $regions = $this->buildRegions($regions, $contexts);
     if ($layout) {
         $regions = $layout->build($regions);
     }
     return $regions;
 }