You are here

function pagination_form_alter in Pagination (Node) 7

Same name and namespace in other branches
  1. 6 pagination.module \pagination_form_alter()

Implementation of hook_form_alter()

File

./pagination.module, line 323

Code

function pagination_form_alter(&$form, $form_state, $form_id) {
  if (strpos($form_id, 'node_form') === FALSE) {
    return;
  }
  $pg = Pagination::instance();
  $paging = $pg
    ->getValue($form['type']['#value']);
  $style = $pg
    ->getStyle($form['type']['#value']);
  $help = '';
  if ($paging) {
    $form['pagination'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('Page headers'),
      '#weight' => -1,
      '#attributes' => array(
        'class' => array(
          'pagination-item-form',
        ),
      ),
    );
    if ($paging == PAGINATION_CUSTOM) {

      // Add helper text for manual paging (custom headers)
      $help .= '<p>' . t('If you would like your article to flow over more than one page, insert a page break within the body of your content at a convenient location:') . '</p>';
      $help .= '<p>' . t('<em>ex. <strong>[ pagebreak ]</strong></em>') . '</p>';
      if ($style > PAGINATION_DEFAULT) {
        $help .= '<p>' . t('In addition, you may set a title for the specific page by using this syntax instead:') . '</p>';
        $help .= '<p>' . t('<em>ex. <strong>[ header = My Section Title ]</strong></em>') . '</p>';
      }
    }
    elseif ($paging == PAGINATION_TAG) {
      $help .= '<p>' . t('Your article pages will break according to the presence of @tag tags. The contents of your @tag will be used as the page title.', array(
        '@tag' => '<h3>',
      )) . '</p>';
    }
    elseif ($paging > PAGINATION_AUTO && $style > PAGINATION_DEFAULT) {
      drupal_add_js(drupal_get_path('module', 'pagination') . '/js/pagination.js');

      //  add helper text for default paging
      $headers = isset($form['nid']['#value']) ? $pg
        ->getHeaders($form['nid']['#value']) : array();
      $form['pagination']['pagination_headers'] = array(
        '#type' => 'textarea',
        '#title' => t('Page headers'),
        '#rows' => 3,
        '#description' => t('You may declare page headers here. The first line represents the title of the 2nd page. Note: the page estimate may be underestimated by one page (or so) in certain circumstances.'),
        '#default_value' => implode("\n", $headers),
        '#suffix' => '<div>' . t('Current page estimate: <span id="pagination-guess">1 page</span> (<span id="pagination-count">%words</span> words per page)', array(
          '%words' => $paging,
        )) . '</div>',
      );
    }
    else {
      $help .= '<p>' . t('Your article will paginate based on an approximation of !number words per page.', array(
        '!number' => $paging,
      )) . '</p>';
    }
    $form['pagination']['#description'] = $help;
  }
}