You are here

function fb_instant_articles_api_fb_page_submit in Facebook Instant Articles 7

Same name and namespace in other branches
  1. 7.2 modules/fb_instant_articles_api/includes/admin.inc \fb_instant_articles_api_fb_page_submit()

Submit handler for Facebook Page selection

1 string reference to 'fb_instant_articles_api_fb_page_submit'
fb_instant_articles_api_module_activation_select_fb_page in modules/fb_instant_articles_api/includes/admin.inc
Generates Facebook Page selection state of Module Activation section

File

modules/fb_instant_articles_api/includes/admin.inc, line 245
Settings for Facebook Instant Articles API module.

Code

function fb_instant_articles_api_fb_page_submit($form, &$form_state) {
  $fb_app_id = variable_get('fb_instant_articles_api_app_id', '');
  $fb_app_secret = variable_get('fb_instant_articles_api_app_secret', '');
  $fb = new Facebook\Facebook([
    'app_id' => $fb_app_id,
    'app_secret' => $fb_app_secret,
    'default_graph_version' => 'v2.5',
  ]);
  $access_token_string = variable_get('fb_instant_articles_api_access_token', '');
  $expires = time() + 60 * 60 * 2;
  $access_token = new Facebook\Authentication\AccessToken($access_token_string, $expires);
  $sdk_helper = new Facebook\InstantArticles\Client\Helper($fb);
  $pages = $sdk_helper
    ->getPagesAndTokens($access_token);
  $fb_page_id = $pages[$form_state['values']['fb_instant_articles_page_id']]['id'];
  variable_set('fb_instant_articles_page_id', $fb_page_id);
  $fb_page_name = $pages[$form_state['values']['fb_instant_articles_page_id']]['name'];
  variable_set('fb_instant_articles_page_name', $fb_page_name);
  $fb_page_access_token = $pages[$form_state['values']['fb_instant_articles_page_id']]['access_token'];
  variable_set('fb_instant_articles_api_access_token', $fb_page_access_token);
  drupal_set_message('Success! This Instant Articles module has been activated.', 'status');
  $form_state['redirect'] = 'admin/config/services/fb-instant-articles/api';
}