aboutsummaryrefslogtreecommitdiff
path: root/jquery_gallery_view.admin.inc
blob: 538850988ec9ea23f2d19061a8f8bab3fb0ccddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

/**
 * @file
 * Admin callbacks.
 */

/**
 * Menu callback.
 */
function jquery_gallery_view() {
  $output  = t('jQuery Gallery View.');
  $output .= drupal_get_form('jquery_gallery_view_form');
  return $output;
}

/**
 * Mass import form.
 */
function jquery_gallery_view_form(&$form_state) {
  $form['node_type'] = array(
    '#type'          => 'select',
    '#title'         => t('Node type'),
    '#options'       => jquery_gallery_view_types(),
    '#default_value' => variable_get('jquery_gallery_view_node_type', array()),
    '#description'   => t('Select node type to import images. For CCK, if node type contains more than one filefield, make sure that the imagefield is the first one.'),
  );

  $form['submit'] = array(
    '#type'  => 'submit',
    '#value' => t('Save'),
  );

  return $form;
}

/**
 * Return the existing content types.
 *
 * @return
 *   Content types.
 */
function jquery_gallery_view_types() {
  $node_types = node_get_types();
  $node_codes = array();

  foreach ($node_types as $item) {
    $node_codes[$item->type] = $item->name;
  }

  return $node_codes;  
}

/**
 * Implementation of hook_validate().
 */
function jquery_gallery_view_form_validate($form, $form_state) {
  if (!isset($form_state['values']['node_type'])) {
    form_set_error('node_type', t('Please choose a content type'));
  }
  else {
    $type  = $form_state['values']['node_type'];  
    $types = node_get_types();

    if (!isset($types[$type])) {
      form_set_error('node_type', t('Invalid content type'));
    }
  }
}