public function PanopolyAdminLayoutsForm::buildForm in Panopoly 8.2
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
- modules/
panopoly/ panopoly_admin/ src/ Form/ PanopolyAdminLayoutsForm.php, line 63
Class
- PanopolyAdminLayoutsForm
- Form to administer the available layouts.
Namespace
Drupal\panopoly_admin\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory
->get('panopoly_admin.settings');
$layouts = $config
->get('layouts');
$form['layouts'] = [
'#type' => 'vertical_tabs',
];
$definitions = $this->layoutManager
->getFilteredDefinitions('layout_builder', NULL, [
'panopoly_admin_layouts_form' => TRUE,
]);
$definitions = $this->layoutManager
->getGroupedDefinitions($definitions);
foreach ($definitions as $group_name => $group) {
$key = $group_name;
if (empty($group_name)) {
$group_name = $this
->t('Miscellaneous');
}
$form[$key] = [
'#type' => 'details',
'#title' => $group_name,
'#group' => 'layouts',
];
foreach ($group as $layout_id => $definition) {
$form[$key][$layout_id] = [
'#type' => 'checkbox',
'#title' => $definition
->getLabel() ?: $layout_id,
'#default_value' => isset($layouts[$layout_id]) ? $layouts[$layout_id] : TRUE,
'#parents' => [
'layout_values',
$layout_id,
],
];
}
}
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
return $form;
}