You are here

function flippy_form_node_type_form_alter in Flippy 7

Implements hook_form_FORM_ID_alter().

File

./flippy.module, line 26
Allows administrators to add previous/next pagers to any node type.

Code

function flippy_form_node_type_form_alter(&$form, $form_state) {
  if (isset($form['type'])) {
    $form['flippy'] = array(
      '#type' => 'fieldset',
      '#title' => t('Flippy settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#group' => 'additional_settings',
    );
    $form['flippy']['flippy'] = array(
      '#type' => 'checkbox',
      '#title' => t('Build a pager for this content type'),
      '#default_value' => isset($form['flippy']['flippy']) ? $form['flippy']['flippy'] : variable_get('flippy_' . $form['#node_type']->type, FALSE),
    );
    $form['flippy']['flippy_head'] = array(
      '#type' => 'checkbox',
      '#title' => t('Add semantic previous and next links to the document HEAD'),
      '#default_value' => isset($form['flippy']['flippy_head']) ? $form['flippy']['flippy_head'] : variable_get('flippy_head_' . $form['#node_type']->type, FALSE),
      '#states' => array(
        'visible' => array(
          // action to take.
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_show_empty'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show empty links'),
      '#default_value' => isset($form['flippy']['flippy_show_empty']) ? $form['flippy']['flippy_show_empty'] : variable_get('flippy_show_empty_' . $form['#node_type']->type, TRUE),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#description' => t('If checked, empty links will be rendered even if there isn\'t a node in the sequence. For example, if there is no "next" node, the "next" label will be shown but without a link. If tokens are being used, it is recommended that this be unchecked.'),
    );
    $form['flippy']['flippy_prev_label'] = array(
      '#type' => 'textfield',
      '#title' => t('Label for "Previous" link'),
      '#size' => 32,
      '#default_value' => isset($form['flippy']['flippy_prev_label']) ? $form['flippy']['flippy_prev_label'] : variable_get('flippy_prev_label_' . $form['#node_type']->type, '‹ ' . t('Previous')),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_next_label'] = array(
      '#type' => 'textfield',
      '#title' => t('Label for "Next" link'),
      '#size' => 32,
      '#default_value' => isset($form['flippy']['flippy_next_label']) ? $form['flippy']['flippy_next_label'] : variable_get('flippy_next_label_' . $form['#node_type']->type, t('Next') . ' ›'),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_firstlast'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show first/last links'),
      '#default_value' => isset($form['flippy']['flippy_firstlast']) ? $form['flippy']['flippy_firstlast'] : variable_get('flippy_firstlast_' . $form['#node_type']->type, FALSE),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_first_label'] = array(
      '#type' => 'textfield',
      '#title' => t('Label for "First" link'),
      '#size' => 32,
      '#default_value' => isset($form['flippy']['flippy_first_label']) ? $form['flippy']['flippy_first_label'] : variable_get('flippy_first_label_' . $form['#node_type']->type, '« ' . t('First')),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy_firstlast]' => array(
            'checked' => TRUE,
          ),
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_last_label'] = array(
      '#type' => 'textfield',
      '#title' => t('Label for "Last" link'),
      '#size' => 32,
      '#default_value' => isset($form['flippy']['flippy_last_label']) ? $form['flippy']['flippy_last_label'] : variable_get('flippy_last_label_' . $form['#node_type']->type, t('Last') . ' »'),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy_firstlast]' => array(
            'checked' => TRUE,
          ),
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_loop'] = array(
      '#type' => 'checkbox',
      '#title' => t('Loop through nodes'),
      '#default_value' => isset($form['flippy']['flippy_loop']) ? $form['flippy']['flippy_loop'] : variable_get('flippy_loop_' . $form['#node_type']->type, FALSE),
      '#states' => array(
        'visible' => array(
          // action to take.
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_random'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show random link'),
      '#default_value' => isset($form['flippy']['flippy_random']) ? $form['flippy']['flippy_random'] : variable_get('flippy_random_' . $form['#node_type']->type, FALSE),
      '#states' => array(
        'visible' => array(
          // action to take.
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_random_label'] = array(
      '#type' => 'textfield',
      '#title' => t('Label for "Random" link'),
      '#size' => 32,
      '#default_value' => isset($form['flippy']['flippy_random_label']) ? $form['flippy']['flippy_random_label'] : variable_get('flippy_random_label_' . $form['#node_type']->type, 'Random'),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy_random]' => array(
            'checked' => TRUE,
          ),
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_token'] = array(
      '#type' => 'fieldset',
      '#title' => t('Browse available tokens'),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_token']['flippy_token_browser'] = array(
      '#theme' => 'token_tree_link',
      '#token_types' => array(
        'node',
      ),
    );
    $form['flippy']['flippy_truncate'] = array(
      '#type' => 'textfield',
      '#title' => t('Truncate label length'),
      '#size' => 32,
      '#default_value' => isset($form['flippy']['flippy_truncate']) ? $form['flippy']['flippy_truncate'] : variable_get('flippy_truncate_' . $form['#node_type']->type, NULL),
      '#description' => t('Optionally provide a maximum amount length that link labels can be. Labels will be shortened to this length if they exceed the amount of characters.'),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_ellipse'] = array(
      '#type' => 'textfield',
      '#title' => t('Truncate ellipse'),
      '#size' => 32,
      '#default_value' => isset($form['flippy']['flippy_ellipse']) ? $form['flippy']['flippy_ellipse'] : variable_get('flippy_ellipse_' . $form['#node_type']->type, '...'),
      '#description' => t('If a maximum label length is set above, an ellipse can be provided here which will be appended to the label after it is shortened.'),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_custom_sorting'] = array(
      '#type' => 'checkbox',
      '#title' => t('Sort the pager by something other than ascending post date'),
      '#default_value' => isset($form['flippy']['flippy_custom_sorting']) ? $form['flippy']['flippy_custom_sorting'] : variable_get('flippy_custom_sorting_' . $form['#node_type']->type, FALSE),
      '#states' => array(
        'visible' => array(
          // action to take.
          ':input[name=flippy]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );

    // Allow certain base table properties for sorting
    $sort_options = _flippy_sorting_properties();

    // Also allow some entity fields
    $content_type_fields = field_info_instances('node', $form['#node_type']->type);
    foreach ($content_type_fields as $sort_field) {
      $field_info = field_info_field($sort_field['field_name']);
      if (isset($field_info['columns']) && isset($field_info['columns']['value'])) {

        // only allow fields that have a 'value' column
        $sort_options[$sort_field['field_name']] = $sort_field['label'];
      }
    }
    $form['flippy']['flippy_sort'] = array(
      '#type' => 'select',
      '#title' => t('Pager sort'),
      '#options' => $sort_options,
      '#default_value' => isset($form['flippy']['flippy_sort']) ? $form['flippy']['flippy_sort'] : variable_get('flippy_sort_' . $form['#node_type']->type, 'created'),
      '#description' => t('Select a field for sorting the pager'),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy_custom_sorting]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['flippy']['flippy_order'] = array(
      '#type' => 'select',
      '#title' => t('Pager order'),
      '#options' => array(
        'ASC' => 'Ascending',
        'DESC' => 'Descending',
      ),
      '#default_value' => isset($form['flippy']['flippy_order']) ? $form['flippy']['flippy_order'] : variable_get('flippy_order_' . $form['#node_type']->type, 'ASC'),
      '#description' => t('Select a direction to order the pager'),
      '#states' => array(
        'visible' => array(
          ':input[name=flippy_custom_sorting]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
}