You are here

function _google_image_sitemap_create_form in Google Image Sitemap 7

Same name and namespace in other branches
  1. 6 google_image_sitemap.module \_google_image_sitemap_create_form()

Form builder: Generate a form to add/edit sitemaps.

1 string reference to '_google_image_sitemap_create_form'
google_image_sitemap_menu in ./google_image_sitemap.module
Implements hook_menu().

File

./google_image_sitemap.module, line 131
A module gives to Google information about images on your site.

Code

function _google_image_sitemap_create_form($form, &$form_state, $sitemap_id = NULL) {
  $form = array();

  // Get all node types.
  $node_types = node_type_get_names();

  // Count the all records from every content types.
  foreach ($node_types as $node_type_key => $node_type_val) {
    $query = db_select('node');
    $query
      ->addExpression('count(*)', 'cnt');
    $query
      ->addExpression('min(nid)', 'min_nid');
    $query
      ->addExpression('max(nid)', 'max_nid');
    $query
      ->condition('type', $node_type_key);
    if ($query
      ->execute()
      ->fetchObject()->cnt != 0) {
      $node_types[$node_type_key] = $node_type_val . " (" . $query
        ->execute()
        ->fetchObject()->min_nid . " - " . $query
        ->execute()
        ->fetchObject()->max_nid . ")";
    }
    else {
      $node_types[$node_type_key] = $node_type_val . " ( 0 - 0 )";
    }
  }
  $form['node_type'] = array(
    '#type' => 'select',
    '#title' => t('Select Content Type'),
    '#description' => t('Select the content type for which you want to generate image sitemap. Starting and Ending Node IDs are also given with each content type.'),
    '#options' => $node_types,
    '#required' => TRUE,
  );
  $form['range_start'] = array(
    '#type' => 'textfield',
    '#title' => t('Range Start'),
    '#description' => t('Starting Node ID.'),
    '#default_value' => '',
    '#required' => TRUE,
  );
  $form['range_end'] = array(
    '#type' => 'textfield',
    '#title' => t('Range End'),
    '#description' => t('Ending Node ID.'),
    '#default_value' => '',
    '#required' => TRUE,
  );
  $form['license'] = array(
    '#type' => 'textfield',
    '#title' => t('License url'),
    '#description' => t('An absolute url to the license agreement of the image.'),
  );
  $form['buttons']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['buttons']['cancel'] = array(
    '#type' => 'link',
    '#href' => isset($_GET['destination']) ? $_GET['destination'] : GOOGLE_IMAGE_SITEMAP_ADMIN_PATH,
    '#title' => t('Cancel'),
  );
  if (!empty($sitemap_id) && ($sitemap_obj = _google_image_sitemap_valid_sitemap_id($sitemap_id))) {
    $form_state['storage']['sitemap_id'] = $sitemap_id;

    // Set default value of form elements.
    $form['node_type']['#default_value'] = $sitemap_obj->node_type;
    $form['license']['#default_value'] = $sitemap_obj->license;
    $form['range_end']['#default_value'] = $sitemap_obj->range_end;
    $form['range_start']['#default_value'] = $sitemap_obj->range_start;
  }
  return $form;
}