You are here

function fb_feed_form in Drupal for Facebook 5.2

File

./fb_feed.module, line 231
Helpers for Facebook feeds (http://wiki.developers.facebook.com/index.php/New_Design_Feed_Wall)

Code

function fb_feed_form(&$node, &$param) {
  $form = array();
  $type = node_get_types('type', $node);

  // We need to define form elements for the node's title and body.
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#weight' => -5,
    '#description' => t('Identifies the template bundle to site administrators.'),
  );
  if ($type->body_label) {
    $form['body_filter']['body'] = array(
      '#type' => 'textarea',
      '#title' => check_plain($type->body_label),
      '#default_value' => $node->body,
      '#required' => FALSE,
      '#description' => 'Not sure yet how this will be used.',
    );
    $form['body_filter']['filter'] = filter_form($node->format);
  }

  // Now we define the form elements specific to our node type.
  $options = fb_get_app_options(FALSE);
  $form['fb_app_nid'] = array(
    '#type' => 'select',
    '#title' => t('Application'),
    '#default_value' => $values['fb_app_nid'],
    '#options' => $options,
    '#description' => t('Which application will use these templates?<br />'),
    '#weight' => -5,
    '#required' => TRUE,
  );
  $form['fb_feed_data'] = array(
    '#tree' => TRUE,
    '#weight' => -4,
  );
  $form['fb_feed_data']['description'] = array(
    '#type' => 'markup',
    '#value' => t('Read <a target=_blank href="!url">about template bundles</a> for more information.', array(
      '!url' => 'http://wiki.developers.facebook.com/index.php/Feed.registerTemplateBundle',
    )),
  );
  $form['fb_feed_data']['example'] = array(
    '#type' => 'markup',
    '#value' => t('Here\'s an example that produces a message like "<em>User Name</em> wrote about <em>something</em> on <em>application</em>," where <em>something</em> is the title of a node:<br/><em>{*actor*} wrote about {*title*} on {*fb-app-title*}</em>'),
  );
  $form['fb_feed_data']['line'] = array(
    '#type' => 'fieldset',
    '#title' => t('One-line templates'),
    '#description' => t('Note that all one-line templates must begin with the {*actor*} token.'),
    '#collapsible' => TRUE,
  );
  $i = 0;
  while ($i < FB_FEED_LINES_PER_BUNDLE) {
    $form['fb_feed_data']['line'][$i] = array(
      '#type' => 'textfield',
      '#title' => t('Additional one-line template'),
      '#default_value' => $node->fb_feed_data['line'][$i],
    );
    $i++;
  }
  $form['fb_feed_data']['line'][0]['#title'] = t('Primary one-line template');
  $form['fb_feed_data']['line'][0]['#required'] = TRUE;
  $form['fb_feed_data']['short'] = array(
    '#type' => 'fieldset',
    '#title' => t('Short templates'),
    '#description' => t('Note that each title must begin with the {*actor*} token.'),
    '#collapsible' => TRUE,
  );
  $i = 0;
  while ($i < FB_FEED_SHORTS_PER_BUNDLE) {
    $form['fb_feed_data']['short'][$i]['template_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Additional short template title'),
      '#default_value' => $node->fb_feed_data['short'][$i]['template_title'],
    );
    $form['fb_feed_data']['short'][$i]['template_body'] = array(
      '#type' => 'textarea',
      '#title' => t('Additional short template body'),
      '#default_value' => $node->fb_feed_data['short'][$i]['template_body'],
      '#rows' => 2,
    );
    $i++;
  }
  $form['fb_feed_data']['short'][0]['template_title']['#title'] = t('Primary short template title');
  $form['fb_feed_data']['short'][0]['template_body']['#title'] = t('Primary short template body');
  $form['fb_feed_data']['full'] = array(
    '#type' => 'fieldset',
    '#title' => t('Full template'),
    '#description' => t(''),
    '#collapsible' => TRUE,
  );
  $form['fb_feed_data']['full']['template_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Full template title'),
    '#default_value' => $node->fb_feed_data['full']['template_title'],
  );
  $form['fb_feed_data']['full']['template_body'] = array(
    '#type' => 'textarea',
    '#title' => t('Full template body'),
    '#default_value' => $node->fb_feed_data['full']['template_body'],
    '#rows' => 8,
  );

  // TODO: If token module enabled
  $form['token_help'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#title' => t("Token help"),
    '#description' => t('Facebook uses the special token {*actor*} for the user performing an action, and {*target*} when the action applies to one (or more) of actor\'s friends.  Otherwise, It is recommended to name your tokens as you would with the token module.  Remember that in Facebook templates you use {*<em>token</em>*} syntax.'),
  );
  foreach (array(
    'node',
    'comment',
    'user',
    'fb_app',
  ) as $type) {
    $form['token_help'][$type] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t("!type tokens", array(
        '!type' => $type,
      )),
      '#description' => theme('token_help', $type, "{*", "*}"),
    );
  }
  return $form;
}