You are here

function scald_dnd_library_form_alter in Scald: Media Management made easy 6

Implements hook_form_alter().

File

scald_dnd_library/scald_dnd_library.module, line 259
Scald DnD Library

Code

function scald_dnd_library_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {

    // Check if the style plugin is scald_library.
    $view = $form['#parameters'][1]['view'];
    if ($view->display_handler
      ->get_option('style_plugin') == 'scald_library') {

      // Put the filters in a fieldset... Hackish.
      $filter = t('Filter');
      drupal_add_js('misc/collapse.js');
      $form['#prefix'] = "<fieldset class='collapsible collapsed'><legend>{$filter}</legend>";
      $form['#suffix'] = "</fieldset>";

      // Try to expose a sort based on the fields defined for this display.
      // That's hackish too, but won't be needed when Views 3 hits a stable
      // release, so let's say it's a temporary workaround.
      $fields = $view->field;
      $options = array();
      foreach ($fields as $name => $field) {
        if ($field->definition['click sortable']) {
          $options[$name] = $field->options['label'];
        }
      }
      if (count($options)) {
        $filter = t('Filter');
        $form['order'] = array(
          '#type' => 'select',
          '#title' => t('Sort'),
          '#options' => $options,
          '#default_value' => $_GET['order'],
        );
        $form['sort'] = array(
          '#type' => 'select',
          '#title' => '',
          '#options' => array(
            'desc' => t('Descending'),
            'asc' => t('Ascending'),
          ),
          '#default_value' => $_GET['sort'],
        );
        $form['submit']['#weight'] = 1;
        $form['reset'] = array(
          '#type' => 'markup',
          '#value' => "<input type='reset' value='" . t('Reset') . "' />",
          '#weight' => 2,
        );
      }
    }
  }
}