You are here

public function EasySocialSettingsForm::buildForm in Easy Social 8.4

Same name and namespace in other branches
  1. 8.3 src/Form/EasySocialSettingsForm.php \Drupal\easy_social\Form\EasySocialSettingsForm::buildForm()

Implements \Drupal\Core\Form\FormInterface::buildForm().

Overrides ConfigFormBase::buildForm

File

src/Form/EasySocialSettingsForm.php, line 72
Contains \Drupal\easy_social\Form\EasySocialSettingsForm.

Class

EasySocialSettingsForm
Configure Easy Social global settings for this site.

Namespace

Drupal\easy_social\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $type = 'new') {
  $config = $this
    ->config('easy_social.settings');
  if ($widgets = easy_social_get_widgets()) {
    $widget_options = array();
    foreach ($widgets as $machine_name => $widget) {
      $widget_options[$machine_name] = $widget['name'];
    }
    $form['widgets'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Enabled widgets'),
      // @TODO decide whether we're going to enable overrides for specific entities and, if so, update the description.
      '#description' => t('Select the social sharing widgets you would like to enable globally. This setting can be overriden per block and entity type.'),
      '#default_value' => (array) $config
        ->get('global.widgets'),
      '#options' => $widget_options,
    );
    $form['advanced'] = array(
      '#type' => 'fieldset',
      '#title' => t('Advanced settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['advanced']['async'] = array(
      '#type' => 'checkbox',
      '#title' => t('Load javascript asynchronously'),
      '#description' => t('This is recommended for performance purposes.'),
      '#default_value' => $config
        ->get('global.async'),
    );
  }
  else {
    $form['widgets_empty'] = array(
      '#prefix' => '<div class="empty">',
      '#suffix' => '</div>',
      '#markup' => t('There are no widgets defined.'),
    );
  }
  return parent::buildForm($form, $form_state);
}