public function FacebookshareSettingsForm::buildForm in Facebook Share 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/ FacebookshareSettingsForm.php, line 36 - Contains \Drupal\facebookshare\Form\FacebookshareSettingsForm.
Class
- FacebookshareSettingsForm
- Administration settings form.
Namespace
Drupal\facebookshare\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Get all settings.
$config = $this
->config('facebookshare.settings');
$settings = $config
->get();
$form['#attached']['library'] = array(
'facebookshare/facebookshare.admin',
);
$form['facebookshare_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Content types'),
'#description' => t('Which content types to apply the Facebook Share button to.'),
'#options' => node_type_get_names(),
'#default_value' => $settings['facebookshare_types'],
);
$form['facebookshare_location'] = array(
'#type' => 'checkboxes',
'#title' => t('Location'),
'#description' => t('Where to show the Facebook Share button.'),
'#options' => array(
'content' => t('Full view'),
'teasers' => t('Teasers'),
),
'#default_value' => $settings['facebookshare_location'],
);
$form['facebookshare_weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight'),
'#description' => t('The weight of which the Facebook widget should appear on the content.'),
'#default_value' => $settings['facebookshare_weight'],
'#size' => 5,
);
$form['facebookshare_app_id'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Facebook Admin ID'),
'#default_value' => $settings['facebookshare_app_id'],
'#description' => $this
->t('Your Facebook Admin Username, ID or App ID. More than one admin can be separated by commas.'),
'#required' => TRUE,
);
$form['facebookshare_size'] = array(
'#type' => 'select',
'#title' => t('Button size'),
'#required' => TRUE,
'#description' => t('What kind of button to show.'),
'#options' => array(
'small' => t('Small'),
'large' => t('Large'),
),
'#default_value' => $settings['facebookshare_size'],
);
$layouts = array(
'box_count',
'button_count',
'button',
);
$options = array();
foreach ($layouts as $layout) {
$options[$layout] = '<img src="' . base_path() . drupal_get_path('module', 'facebookshare') . '/images/' . $layout . '.png">';
}
$form['facebookshare_layout'] = array(
'#type' => 'radios',
'#title' => t('Button size'),
'#required' => TRUE,
'#description' => t('What kind of button to show.'),
'#options' => $options,
'#default_value' => $settings['facebookshare_layout'],
);
$form['facebookshare_mobile_iframe'] = array(
'#type' => 'checkbox',
'#title' => t('Mobile Iframe'),
'#default_value' => $settings['facebookshare_mobile_iframe'],
);
$form['facebookshare_width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => $settings['facebookshare_width'],
'#size' => 4,
'#maxlength' => 4,
'#required' => TRUE,
);
$form['facebookshare_height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => $settings['facebookshare_height'],
'#size' => 4,
'#maxlength' => 4,
'#required' => TRUE,
);
return parent::buildForm($form, $form_state);
}