You are here

function fb_permissions_facebook_permissions_settings in Facebook Autopost 7

FAPI settings callback for Facebook app permissions.

See also

https://developers.facebook.com/docs/facebook-login/permissions/v2.0#ref...

1 string reference to 'fb_permissions_facebook_permissions_settings'
fb_permissions_menu in fb_permissions/fb_permissions.module
Implements hook_menu().

File

fb_permissions/fb_permissions.module, line 50
Module implementation file.

Code

function fb_permissions_facebook_permissions_settings($form, &$form_state) {
  $version = empty($form_state['values']['version']) ? 'v2.0' : $form_state['values']['version'];
  $form['version'] = array(
    '#type' => 'radios',
    '#title' => t('Version'),
    '#description' => t('Facebook login API permissions version.'),
    '#options' => array(
      'v1.0' => t('v1.0 - Legacy.'),
      'v2.0' => t('v2.0'),
    ),
    '#default_value' => $version,
    '#required' => TRUE,
  );
  $form['role'] = array(
    '#type' => 'select',
    '#title' => t('Role'),
    '#description' => t('Select the role you need to specify the permissions for. The form will reload to reflect the default values for that role.'),
    '#required' => TRUE,
    '#options' => user_roles(),
    '#ajax' => array(
      'callback' => 'fb_permissions_role_permissions',
      // Replace the whole form.
      'wrapper' => 'fb-permissions-facebook-permissions-settings',
      'effect' => 'fade',
    ),
  );
  $form['facebook_permissions'] = array(
    '#type' => 'vertical_tabs',
    '#default_tab' => 'edit-extended-permissions',
  );
  $config = fb_permissions_default_permissions($version);
  if (!empty($form_state['values']['role'])) {
    $values = variable_get('fb_permissions_facebook_permissions:' . $form_state['values']['role'], array(
      'public_profile',
      'publish_actions',
    ));
    $values = array_map('replace_dot_vertical_bar', $values);
    foreach ($config as $perm_group => $group_item) {
      $permissions = $group_item['permissions'];
      unset($group_item['permissions']);
      $form['facebook_permissions'][$perm_group] = $group_item;
      $form['facebook_permissions'][$perm_group]['#type'] = 'fieldset';
      foreach ($permissions as $perm_id => $permission_item) {
        $form['facebook_permissions'][$perm_group][$perm_id] = $permission_item;
        $form['facebook_permissions'][$perm_group][$perm_id]['#type'] = 'checkbox';
        $form['facebook_permissions'][$perm_group][$perm_id]['#default_value'] = in_array($perm_id, $values);
      }
    }

    // Make sure the mandatory actions are checked.
    if (!empty($form['facebook_permissions']['public_profile']['public_profile'])) {
      $form['facebook_permissions']['public_profile']['public_profile']['#value'] = TRUE;
      $form['facebook_permissions']['public_profile']['public_profile']['#default_value'] = TRUE;
      $form['facebook_permissions']['public_profile']['public_profile']['#disabled'] = TRUE;
    }
    if (!empty($form['facebook_permissions']['extended_permissions_publish']['publish_actions'])) {
      $form['facebook_permissions']['extended_permissions_publish']['publish_actions']['#value'] = TRUE;
      $form['facebook_permissions']['extended_permissions_publish']['publish_actions']['#default_value'] = TRUE;
      $form['facebook_permissions']['extended_permissions_publish']['publish_actions']['#disabled'] = TRUE;
    }
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save configuration'),
    );
  }
  return $form;
}