From 7af5924b4a54c5363de88849df0eac49f7d6fe9d Mon Sep 17 00:00:00 2001 From: Silvio Date: Wed, 20 Oct 2010 17:56:41 -0200 Subject: Adding admin functions --- jquery_gallery_view.admin.inc | 69 +++++++++++++++++++++++++++++++++++++++++++ jquery_gallery_view.module | 33 +++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 jquery_gallery_view.admin.inc diff --git a/jquery_gallery_view.admin.inc b/jquery_gallery_view.admin.inc new file mode 100644 index 0000000..5388509 --- /dev/null +++ b/jquery_gallery_view.admin.inc @@ -0,0 +1,69 @@ + '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')); + } + } +} diff --git a/jquery_gallery_view.module b/jquery_gallery_view.module index 539433a..6ac2c58 100644 --- a/jquery_gallery_view.module +++ b/jquery_gallery_view.module @@ -6,6 +6,39 @@ * jQuery GalleryView module. */ +/** + * Implementation of hook_menu(). + */ +function jquery_gallery_view_menu() { + $items['admin/settings/jquery_gallery_view'] = array( + 'title' => t('jQuery Gallery View'), + 'description' => t('Configure settings for jQuery Gallery View.'), + 'page callback' => 'jquery_gallery_view', + 'access arguments' => array('administer content'), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'jquery_gallery_view.admin.inc', + ); + + return $items; +} + +/** + * Get the first filefield from a content type. + * + * @param $fields + * Content type fields. + * + * @return + * Field name. + */ +function jquery_gallery_view_field($fields) { + foreach ($fields as $field) { + if ($field['type'] == 'filefield') { + return $field['field_name']; + } + } +} + /** * Setup photos for a view. * -- cgit v1.2.3