You are here

public function LayoutChangeSettings::buildForm in Panels 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/LayoutChangeSettings.php \Drupal\panels\Form\LayoutChangeSettings::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/LayoutChangeSettings.php, line 69

Class

LayoutChangeSettings
Provides a form for configuring a layout's settings.

Namespace

Drupal\panels\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');

  /* @var $variant_plugin \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant */
  $variant_plugin = $cached_values['plugin'];
  $form['old_layout'] = [
    '#title' => $this
      ->t('Old Layout'),
    '#type' => 'select',
    '#options' => Layout::getLayoutOptions([
      'group_by_category' => TRUE,
    ]),
    '#default_value' => !empty($cached_values['layout_change']['old_layout']) ? $cached_values['layout_change']['old_layout'] : '',
    '#disabled' => TRUE,
    '#access' => !empty($cached_values['layout_change']),
  ];
  $form['new_layout'] = [
    '#title' => $this
      ->t('New Layout'),
    '#type' => 'select',
    '#options' => Layout::getLayoutOptions([
      'group_by_category' => TRUE,
    ]),
    '#default_value' => !empty($cached_values['layout_change']['new_layout']) ? $cached_values['layout_change']['new_layout'] : '',
    '#disabled' => TRUE,
    '#access' => !empty($cached_values['layout_change']),
  ];

  // If a layout is already selected, show the layout settings.
  $form['layout_settings_wrapper'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Layout settings'),
    '#tree' => TRUE,
  ];
  $layout_settings = !empty($cached_values['layout_change']['layout_settings']) ? $cached_values['layout_change']['layout_settings'] : [];
  if (!$layout_settings && $variant_plugin
    ->getLayout() instanceof ConfigurablePluginInterface) {
    $layout_settings = $variant_plugin
      ->getLayout()
      ->getConfiguration();
  }
  $layout_id = !empty($cached_values['layout_change']['new_layout']) ? $cached_values['layout_change']['new_layout'] : $variant_plugin
    ->getConfiguration()['layout'];
  $layout = Layout::layoutPluginManager()
    ->createInstance($layout_id, $layout_settings);
  $form['layout_settings_wrapper']['layout_settings'] = $layout
    ->buildConfigurationForm([], $form_state);
  return $form;
}