You are here

function fb_instant_articles_display_form_node_type_form_alter in Facebook Instant Articles 7.2

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

Implements hook_form_FORM_ID_alter().

@todo Decouple from alter hook to more easily support other entity types.

See also

fb_instant_articles_display_node_type_form_submit()

File

modules/fb_instant_articles_display/fb_instant_articles_display.module, line 166
Hook implementations for Facebook Instant Articles Display module.

Code

function fb_instant_articles_display_form_node_type_form_alter(&$form, &$form_state) {

  // Add a vertical tab to the node type form.
  if (user_access('administer fb_instant_articles_display')) {

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

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

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

    // Is an Article type?
    $type = $form['#node_type']->type;
    $fb_instant_enabled = fb_instant_articles_display_is_article_type('node', $type);
    $previously_checked = isset($form_state['values']) && $form_state['values']['fb_instant_articles_display']['fb_instant_enabled'];

    // Build the product checkbox.
    $form['fb_instant_articles_display']['fb_instant_enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Include Content Type in Facebook Instant Articles feed.'),
      '#description' => t('Enable content of this type to be included in the Facebook Instant Articles feed.'),
      '#weight' => 0,
      '#default_value' => $previously_checked || $fb_instant_enabled ? TRUE : FALSE,
    );

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