public function PanelsIPELayoutForm::buildForm in Panels 8.3
Same name and namespace in other branches
- 8.4 panels_ipe/src/Form/PanelsIPELayoutForm.php \Drupal\panels_ipe\Form\PanelsIPELayoutForm::buildForm()
Builds a form that configure an existing or new layout for the IPE.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
string $layout_id: The requested Layout ID.
\Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display: The current PageVariant ID.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- panels_ipe/
src/ Form/ PanelsIPELayoutForm.php, line 100
Class
- PanelsIPELayoutForm
- Provides a form for configuring a layout for use with the IPE.
Namespace
Drupal\panels_ipe\FormCode
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 or auto-submit if they are changing
// layouts.
if (empty(Element::getVisibleChildren($form['settings']))) {
if ($current) {
$form['settings'][] = [
'#markup' => $this
->t('<h5>This layout does not provide any configuration.</h5>'),
];
}
else {
$this
->submitForm($form, $form_state);
}
}
// 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;
}