You are here

protected function ApiSettingsForm::moduleActivationBuildForm 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::moduleActivationBuildForm()

Generate the module activation section of the settings form.

Parameters

array $form: Form array.

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

Return value

array Form array.

1 call to ApiSettingsForm::moduleActivationBuildForm()
ApiSettingsForm::buildForm in src/Form/ApiSettingsForm.php
Form constructor.

File

src/Form/ApiSettingsForm.php, line 91

Class

ApiSettingsForm
Facebook Instant Articles API form.

Namespace

Drupal\fb_instant_articles\Form

Code

protected function moduleActivationBuildForm(array $form, FormStateInterface $form_state) {

  // If the person is coming back to edit FB app settings, drop them back into
  // the correct state.
  $edit_state = '';
  if ($edit = $this->currentRequest
    ->get('edit')) {
    $edit_state = $edit;
  }
  $config = $this
    ->config('fb_instant_articles.settings');

  // Grab the current module settings from the database to determine where
  // the person is in the configuration state.
  $app_id = $config
    ->get('app_id');
  $app_secret = $config
    ->get('app_secret');
  $access_token = trim($config
    ->get('access_token'));
  $page_id = $config
    ->get('page_id');

  // If the App ID or App Secret haven't been configured for the module yet,
  // drop the person into the initial state.
  if (empty($app_id) || empty($app_secret) || $edit_state === 'fb_app_settings') {
    $form = $this
      ->moduleActivationFbAppSettings($form, $app_id, $app_secret);
  }
  elseif (empty($access_token)) {
    $form = $this
      ->moduleActivationConnectFbAccount($form, $app_id, $app_secret);
  }
  elseif (empty($page_id) || $edit_state === 'fb_page') {
    $form = $this
      ->moduleActivationSelectFbPage($form, $app_id, $app_secret, $access_token, $page_id);
  }
  else {
    $form = $this
      ->moduleActivationSummary($form, $app_id, $page_id);
  }
  return $form;
}