You are here

function fb_instant_articles_rss_form_node_form_alter in Facebook Instant Articles 7.2

Same name and namespace in other branches
  1. 7 modules/fb_instant_articles_rss/fb_instant_articles_rss.module \fb_instant_articles_rss_form_node_form_alter()

Implements hook_form_BASE_FORM_ID_alter().

File

modules/fb_instant_articles_rss/fb_instant_articles_rss.module, line 157
Facebook Instant Articles RSS module.

Code

function fb_instant_articles_rss_form_node_form_alter(&$form, &$form_state, $form_id) {
  $is_article_type = fb_instant_articles_display_is_article_type('node', $form['#node']->type);
  if (user_access('administer fb_instant_articles_rss') && $is_article_type) {

    // Build fieldset for vertical tab section.
    $fieldset = array(
      '#type' => 'fieldset',
      '#title' => t('Facebook Instant Articles'),
      '#description' => t('Facebook Instant Articles RSS settings.'),
      '#group' => 'additional_settings',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );

    // Has the section already been created (perhaps by a sub module)?
    if (isset($form['fb_instant_articles_rss'])) {

      // Add additional fieldset data.
      $form['fb_instant_articles_rss'] += $fieldset;
    }
    else {
      $form['fb_instant_articles_rss'] = $fieldset;
    }

    // Is an Article?
    $type = $form['#node']->type;
    if (!empty($form['#node']->nid)) {
      $fb_instant_enabled = fb_instant_articles_rss_is_article($form['#node']->nid);
    }
    else {
      $fb_instant_enabled = fb_instant_articles_display_is_article_type('node', $type);
    }
    $previously_checked = isset($form_state['values']) && $form_state['values']['fb_instant_articles_rss']['fb_instant_enabled'];
    $form['fb_instant_articles_rss']['fb_instant_enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Include in Facebook Instant Articles RSS feed.'),
      '#description' => t('Enable this entity to be included in the Facebook Instant Articles RSS feed.'),
      '#weight' => 0,
      '#default_value' => $previously_checked || $fb_instant_enabled ? TRUE : FALSE,
    );

    // Add custom submit.
    $form['#submit'][] = 'fb_instant_articles_rss_node_form_submit';
  }
}