public function BrowserGroupsForm::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 EntityForm::buildForm
File
- src/
Form/ BrowserGroupsForm.php, line 79 - Contains \Drupal\paragraphs_browser\Form\BrowserGroupsForm.
Class
- BrowserGroupsForm
- Class CleanupUrlAliases.
Namespace
Drupal\paragraphs_browser\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'paragraphs_browser/modal';
$browser_type = $this->entity;
$form = parent::buildForm($form, $form_state);
$form['groups'] = array(
'#type' => 'table',
'#header' => array(
'Label',
'Machine',
'Weight',
'',
),
'#tabledrag' => array(
array(
'action' => 'order',
'relationship' => 'sibling',
'group' => 'element-weight',
),
),
);
foreach ($browser_type
->groupManager()
->getGroups() as $group) {
$row = array();
$row['#attributes']['class'][] = 'draggable';
$row['#weight'] = $group
->getWeight();
$row['label'] = array(
'#type' => 'item',
'#markup' => $group
->getLabel(),
'#default_value' => $group
->getLabel(),
);
$row['machine_name'] = array(
'#type' => 'item',
'#markup' => $group
->getId(),
'#default_value' => $group
->getId(),
);
$row['weight'] = array(
'#title' => 'Weight',
'#type' => 'textfield',
'#default_value' => $group
->getWeight(),
'#attributes' => array(
'class' => array(
'element-weight',
),
),
);
$operations = array(
'edit' => array(
'title' => $this
->t('Edit'),
'url' => Url::fromRoute('paragraphs_browser.paragraphs_browser_type.group_edit_form', array(
'paragraphs_browser_type' => $browser_type
->id(),
'group_machine_name' => $group
->getId(),
)),
),
'delete' => array(
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('paragraphs_browser.paragraphs_browser_type.group_delete_form', array(
'paragraphs_browser_type' => $browser_type
->id(),
'group_machine_name' => $group
->getId(),
)),
),
);
$row['operations'] = array(
'#type' => 'operations',
'#links' => $operations,
);
$form['groups'][$group
->getId()] = $row;
}
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#button_type' => 'primary',
);
$form['actions'] = $this
->actionsElement($form, $form_state);
return $form;
}