You are here

protected function ApiSettingsForm::moduleActivationSelectFbPage in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/ApiSettingsForm.php \Drupal\fb_instant_articles\Form\ApiSettingsForm::moduleActivationSelectFbPage()

Generates state of FB account connection for Module Activation section.

Parameters

array $form: FAPI array.

string $app_id: Facebook application id.

string $app_secret: Facebook application secret.

string $access_token: Facebook access token.

string $page_id: Facebook page id.

Return value

array FAPI array.

1 call to ApiSettingsForm::moduleActivationSelectFbPage()
ApiSettingsForm::moduleActivationBuildForm in src/Form/ApiSettingsForm.php
Generate the module activation section of the settings form.

File

src/Form/ApiSettingsForm.php, line 285

Class

ApiSettingsForm
Facebook Instant Articles API form.

Namespace

Drupal\fb_instant_articles\Form

Code

protected function moduleActivationSelectFbPage(array $form, $app_id, $app_secret, $access_token, $page_id) {
  $fb = new Facebook([
    'app_id' => $app_id,
    'app_secret' => $app_secret,
    'default_graph_version' => 'v2.5',
  ]);
  $expires = time() + 60 * 60 * 2;
  $access_token = new AccessToken($access_token, $expires);
  $sdk_helper = new Helper($fb);
  $pages = $sdk_helper
    ->getPagesAndTokens($access_token);
  $form['module_activation'] = [
    '#type' => 'details',
    '#title' => t('Module activation'),
    '#open' => TRUE,
  ];
  $form['module_activation']['fb_app_settings'] = [
    '#markup' => '<p>' . $this
      ->t('Your Facebook App ID is <strong>@app_id</strong>. <a href="?edit=fb_app_settings">Update Facebook app id</a>.', [
      '@app_id' => $app_id,
    ]) . '</p>',
  ];
  $page_options = [];
  foreach ($pages as $page) {
    $page_options[$page
      ->getField('id')] = $page
      ->getField('name');
  }
  $form['module_activation']['page_id'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Facebook page'),
    '#description' => $this
      ->t('Select the Facebook page where you will publish Instant Articles.'),
    '#options' => $page_options,
    '#default_value' => $page_id,
  ];
  $form['module_activation']['next'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Next'),
    '#submit' => [
      [
        $this,
        'fbPageSubmit',
      ],
    ],
  ];
  return $form;
}