public function LayoutParagraphsSectionsSettingsForm::buildForm in Layout Paragraphs 2.0.x
Same name and namespace in other branches
- 1.0.x src/Form/LayoutParagraphsSectionsSettingsForm.php \Drupal\layout_paragraphs\Form\LayoutParagraphsSectionsSettingsForm::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 ConfigFormBase::buildForm
File
- src/
Form/ LayoutParagraphsSectionsSettingsForm.php, line 107
Class
- LayoutParagraphsSectionsSettingsForm
- Class LayoutParagraphsSectionsSettingsForm.
Namespace
Drupal\layout_paragraphs\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$paragraph_bundles = $this->entityTypeBundleInfo
->getBundleInfo('paragraph');
$form['description'] = [
'#type' => 'markup',
'#markup' => '<p>' . $this
->t('Choose at least one paragraph type to use as a Layout Section.') . '</p>',
];
$layout_options = $this->layoutPluginManager
->getLayoutOptions();
$paragraphs_type_storage = $this->entityTypeManager
->getStorage('paragraphs_type');
foreach ($paragraph_bundles as $name => $paragraph_bundle) {
/** @var \Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type */
$paragraphs_type = $paragraphs_type_storage
->load($name);
$layout_paragraphs_behavior = $paragraphs_type
->getBehaviorPlugin('layout_paragraphs');
$layout_paragraphs_behavior_config = $layout_paragraphs_behavior
->getConfiguration();
$form[$name] = [
'#type' => 'fieldset',
'#title' => $paragraph_bundle['label'],
'#description' => $paragraphs_type
->getDescription(),
];
$form[$name][$name] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use as a Layout Section'),
'#default_value' => !empty($layout_paragraphs_behavior_config['enabled']),
];
$form[$name][$name . '_layouts'] = [
'#type' => 'select',
'#title' => $this
->t('Available Layouts for @label Paragraphs', [
'@label' => $paragraph_bundle['label'],
]),
'#options' => $layout_options,
'#multiple' => TRUE,
'#default_value' => array_keys($layout_paragraphs_behavior_config['available_layouts']),
'#size' => count($layout_options) < 8 ? count($layout_options) * 2 : 10,
'#states' => [
'visible' => [
':input[name="' . $name . '"]' => [
'checked' => TRUE,
],
],
],
];
}
return parent::buildForm($form, $form_state);
}