You are here

function linkedin_status_update_form_elements in LinkedIn Integration 7

@todo Please document this function.

See also

http://drupal.org/node/1354

1 call to linkedin_status_update_form_elements()
linkedin_status_form_alter in linkedin_status/linkedin_status.module

File

linkedin_status/linkedin_status.pages.inc, line 133

Code

function linkedin_status_update_form_elements($node, $user) {

  // set up the state of the checkbox in the form
  if (isset($user->data['linkedin_status_enabled_by_default']) && $user->data['linkedin_status_enabled_by_default'] == 1 && !isset($node->nid)) {
    $checked = 1;
  }
  else {
    $checked = 0;
  }

  //prepare the form base checkbox
  $elems['linkedin_status'] = array(
    '#type' => 'fieldset',
    '#title' => t('Post to LinkedIn'),
    '#tree' => TRUE,
  );
  $elems['linkedin_status']['posting'] = array(
    '#type' => 'checkbox',
    '#id' => 'linkedin-status-posting',
    '#default_value' => $checked,
  );
  $elems['linkedin_status']['posting']['#title'] = t('Announce on LinkedIn');

  //check if user can post to LinkedIn. No need to load all the following if the form is to be disabled anyway
  $check = linkedin_get_profile_fields($user->uid, array(
    'id',
  ));
  if (!isset($check['id'])) {

    //disabling form for users who have not yet authorised our site and link them to the right place
    $elems['linkedin_status']['posting']['#disabled'] = TRUE;
    $elems['linkedin_status']['posting']['#prefix'] = '<p>' . t('You must first authorize this feature in your user profile : !url', array(
      '!url' => l($user->name, 'user/' . $user->uid . '/edit/linkedin'),
    )) . '</p>';
  }
  else {

    //user can post

    //add textfield is user has perm.
    if (user_access('use custom status text')) {

      // two lines of js for hiding the texfield if checkbox is unchecked.
      drupal_add_js(drupal_get_path('module', 'linkedin_status') . '/linkedin_status.js');
      $elems['linkedin_status']['status'] = array(
        '#type' => 'textfield',
        '#default_value' => variable_get('linkedin_status_default_format_' . $node->type, ''),
        '#description' => t('This text will be set as your current status on linkedin. You can use !title, !url, !user and !site as replacement text.'),
        '#id' => 'linkedin-status-textfield',
      );
    }
    else {
      $elems['linkedin_status']['status'] = array(
        '#type' => 'hidden',
        '#value' => variable_get('linkedin_status_default_format_' . $node->type, ''),
      );
    }
  }
  return $elems;
}