You are here

public function CustomForm::buildForm in Facebook Comments Box 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/CustomForm.php, line 52

Class

CustomForm
Configure custom settings for this site.

Namespace

Drupal\facebook_comments_box\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['facebook_comments_box_global'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global Settings'),
    '#collapsible' => TRUE,
  );
  $form['facebook_comments_box_global']['facebook_comments_box_admin_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Facebook Admin ID'),
    '#default_value' => $this
      ->config('facebook_comments_box.settings')
      ->get('facebook_comments_box_admin_id'),
    '#description' => t('Your Facebook Admin Username, ID or App ID. More than one admin can be separated by commas.'),
    '#required' => TRUE,
  );
  $form['facebook_comments_box_default_block'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default Block Settings'),
    '#collapsible' => TRUE,
  );
  $form['facebook_comments_box_default_block']['facebook_comments_box_default_comments'] = array(
    '#type' => 'select',
    '#title' => t('Default Number of Comments'),
    '#default_value' => $this
      ->config('facebook_comments_box.settings')
      ->get('facebook_comments_box_default_comments'),
    '#options' => array(
      10 => 10,
      20 => 20,
      30 => 30,
      50 => 50,
      100 => 100,
    ),
    '#description' => t('The number of comments to show by default on the page displaying them.'),
    '#required' => TRUE,
  );
  $form['facebook_comments_box_default_block']['facebook_comments_box_default_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Default Width of Comments (in pixels)'),
    '#default_value' => $this
      ->config('facebook_comments_box.settings')
      ->get('facebook_comments_box_default_width'),
    '#size' => 4,
    '#maxlength' => 4,
    '#description' => t('The width of the comments with a minimum of 400px.'),
    '#required' => TRUE,
  );
  $form['facebook_comments_box_default_block']['facebook_comments_box_default_theme'] = array(
    '#type' => 'select',
    '#title' => t('Default Theme'),
    '#default_value' => $this
      ->config('facebook_comments_box.settings')
      ->get('facebook_comments_box_default_theme'),
    '#options' => array(
      'light' => t('Light'),
      'dark' => t('Dark'),
    ),
    '#description' => t('The default theme to use for comments.'),
    '#required' => TRUE,
  );

  //Store the node type keys as values for easier comparison.
  $fcb_all_node_types_keys = array_keys(node_type_get_types());
  $fcb_all_node_types = array();
  foreach ($fcb_all_node_types_keys as $node_type) {
    $fcb_all_node_types[$node_type] = $node_type;
  }
  $form['facebook_comments_box_default_block']['facebook_comments_box_default_node_types'] = array(
    '#type' => 'select',
    '#title' => t('Default Node Types'),
    '#default_value' => $this
      ->config('facebook_comments_box.settings')
      ->get('facebook_comments_box_node_types'),
    '#options' => $fcb_all_node_types,
    '#multiple' => TRUE,
    '#description' => t('The node types to attach comments to. This will make comments available for each of the selected node types.'),
    '#required' => TRUE,
  );
  return parent::buildForm($form, $form_state);
}