public function ParagraphTypeGroupsForm::buildForm in Paragraphs Browser 8
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/ ParagraphTypeGroupsForm.php, line 79 - Contains \Drupal\paragraphs_browser\Form\ParagraphsTypeGroupForm.
Class
- ParagraphTypeGroupsForm
- Class CleanupUrlAliases.
Namespace
Drupal\paragraphs_browser\FormCode
public function buildForm(array $form, FormStateInterface $form_state, ParagraphsTypeInterface $paragraphs_type = null) {
$paragraph_browser_type_ids = $this->entityTypeManager
->getStorage('paragraphs_browser_type')
->getQuery()
->execute();
//@todo: on unsaved change, hide links to configuration forms.
if (!$paragraph_browser_type_ids) {
// @todo set message and link to page
return;
}
$paragraph_browser_types = array();
$form['paragraph_browser_type'] = array(
'#type' => 'container',
'#tree' => TRUE,
);
foreach ($paragraph_browser_type_ids as $machine_name) {
$paragraph_browser_type = BrowserType::load($machine_name);
$paragraph_browser_types[$machine_name] = $paragraph_browser_type;
$form['paragraph_browser_type'][$machine_name] = array(
'#type' => 'fieldset',
'#title' => $paragraph_browser_type
->label(),
);
if ($groups = $paragraph_browser_type
->groupManager()
->getGroups()) {
$options = array(
'_na' => '-- Not Defined --',
);
foreach ($groups as $group_machine_name => $group) {
$options[$group_machine_name] = $group
->getLabel();
}
$form['paragraph_browser_type'][$machine_name]['group'] = array(
'#type' => 'select',
'#title' => $paragraph_browser_type
->label(),
'#title_display' => 'hidden',
'#options' => $options,
'#default_value' => $paragraph_browser_type
->getGroupMap($paragraphs_type
->id()),
);
}
else {
$form['paragraph_browser_type'][$machine_name]['group'] = array(
'#type' => 'markup',
'#markup' => 'No groups defined.',
);
}
}
$form_state
->addBuildInfo('paragraph_browser_types', $paragraph_browser_types);
$form_state
->addBuildInfo('paragraph_type', $paragraphs_type);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#button_type' => 'primary',
'#submit' => array(
'::submitForm',
'::save',
),
);
return $form;
}