public function ResponsiveShareButtonsForm::buildForm in Responsive Share Buttons 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 ConfigFormBase::buildForm
File
- src/
Form/ ResponsiveShareButtonsForm.php, line 32
Class
- ResponsiveShareButtonsForm
- Responsive share buttons configuration form.
Namespace
Drupal\responsive_share_buttons\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('responsive_share_buttons.settings');
// Get the current networks, sorted by weight.
$networks = $config
->get('networks');
uasort($networks, [
'Drupal\\Component\\Utility\\SortArray',
'sortByWeightElement',
]);
$form['networks'] = [
'#type' => 'table',
'#id' => 'draggable-table',
'#caption' => $this
->t('Networks for sharing.'),
'#header' => [
$this
->t('Network'),
$this
->t('Name'),
$this
->t('Active'),
$this
->t('Weight'),
],
'#tabledrag' => [
[
'table_id' => 'draggable-table',
'action' => 'order',
'relationship' => 'sibling',
'group' => 'table-order-weight',
],
],
];
foreach ($networks as $name => $network) {
$form['networks'][$name] = [
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#type' => 'hidden',
'#value' => $name,
],
'network' => [
'#plain_text' => $name,
],
'active' => [
'#type' => 'checkbox',
'#title_display' => 'invisible',
'#default_value' => isset($network['active']) ? $network['active'] : FALSE,
],
'weight' => [
'#type' => 'weight',
'#title_display' => 'invisible',
'#default_value' => isset($network['weight']) ? $network['weight'] : 0,
'#attributes' => [
'class' => [
'table-order-weight',
],
],
],
];
}
$form['twitter_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Twitter username'),
'#default_value' => $config
->get('twitter_name', ''),
'#description' => $this
->t('Add a twitter name for tweets to include a via mention'),
];
return parent::buildForm($form, $form_state);
}