You are here

public function FacebookAuthSettingsForm::buildForm in Social Auth Facebook 8.2

Same name and namespace in other branches
  1. 8 src/Form/FacebookAuthSettingsForm.php \Drupal\social_auth_facebook\Form\FacebookAuthSettingsForm::buildForm()
  2. 3.x src/Form/FacebookAuthSettingsForm.php \Drupal\social_auth_facebook\Form\FacebookAuthSettingsForm::buildForm()

File

src/Form/FacebookAuthSettingsForm.php, line 77

Class

FacebookAuthSettingsForm
Settings form for Social Auth Facebook.

Namespace

Drupal\social_auth_facebook\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('social_auth_facebook.settings');
  $form['fb_settings'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Facebook App settings'),
    '#open' => TRUE,
    '#description' => $this
      ->t('You need to first create a Facebook App at <a href="@facebook-dev">@facebook-dev</a>', [
      '@facebook-dev' => 'https://developers.facebook.com/apps',
    ]),
  ];
  $form['fb_settings']['app_id'] = [
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => $this
      ->t('Application ID'),
    '#default_value' => $config
      ->get('app_id'),
    '#description' => $this
      ->t('Copy the App ID of your Facebook App here. This value can be found from your App Dashboard.'),
  ];
  $form['fb_settings']['app_secret'] = [
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => $this
      ->t('App Secret'),
    '#default_value' => $config
      ->get('app_secret'),
    '#description' => $this
      ->t('Copy the App Secret of your Facebook App here. This value can be found from your App Dashboard.'),
  ];
  $form['fb_settings']['graph_version'] = [
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => $this
      ->t('Facebook Graph API version'),
    '#default_value' => $config
      ->get('graph_version'),
    '#description' => $this
      ->t('Copy the API Version of your Facebook App here. This value can be found from your App Dashboard. More information on API versions can be found at <a href="@facebook-changelog">Facebook Platform Changelog</a>', [
      '@facebook-changelog' => 'https://developers.facebook.com/docs/apps/changelog',
    ]),
  ];
  $form['fb_settings']['oauth_redirect_url'] = [
    '#type' => 'textfield',
    '#disabled' => TRUE,
    '#title' => $this
      ->t('Valid OAuth redirect URIs'),
    '#description' => $this
      ->t('Copy this value to <em>Valid OAuth redirect URIs</em> field of your Facebook App settings.'),
    '#default_value' => Url::fromRoute('social_auth_facebook.callback')
      ->setAbsolute()
      ->toString(),
  ];
  $form['fb_settings']['app_domains'] = [
    '#type' => 'textfield',
    '#disabled' => TRUE,
    '#title' => $this
      ->t('App Domains'),
    '#description' => $this
      ->t('Copy this value to <em>App Domains</em> field of your Facebook App settings.'),
    '#default_value' => $this->requestContext
      ->getHost(),
  ];
  $form['fb_settings']['site_url'] = [
    '#type' => 'textfield',
    '#disabled' => TRUE,
    '#title' => $this
      ->t('Site URL'),
    '#description' => $this
      ->t('Copy this value to <em>Site URL</em> field of your Facebook App settings.'),
    '#default_value' => $GLOBALS['base_url'],
  ];
  $form['fb_settings']['advanced'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced settings'),
    '#open' => FALSE,
  ];
  $form['fb_settings']['advanced']['scopes'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Scopes for API call'),
    '#default_value' => $config
      ->get('scopes'),
    '#description' => $this
      ->t('Define any additional scopes to be requested, separated by a comma (e.g.: user_birthday,user_location).<br>
                                  The scopes \'email\' and \'public_profile\' are added by default and always requested.<br>
                                  You can see the full list of valid scopes and their description <a href="@scopes">here</a>.', [
      '@scopes' => 'https://developers.facebook.com/docs/facebook-login/permissions/',
    ]),
  ];
  $form['fb_settings']['advanced']['endpoints'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('API calls to be made to collect data'),
    '#default_value' => $config
      ->get('endpoints'),
    '#description' => $this
      ->t('Define the Endpoints to be requested when user authenticates with Facebook for the first time<br>
                                  Enter each endpoint in different lines in the format <em>endpoint</em>|<em>name_of_endpoint</em>.<br>
                                  <b>For instance:</b><br>
                                  /me?fields=birthday|user_birthday<br>
                                  /me?fields=address|user_address'),
  ];
  return parent::buildForm($form, $form_state);
}