You are here

function _google_image_sitemap_create_form in Google Image Sitemap 6

Same name and namespace in other branches
  1. 7 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, $sitemap_id = NULL) {
  $form = array();

  // Get all node types.
  $node_types = node_get_types('names');

  // Count the all records from every content types.
  foreach ($node_types as $node_type_key => $node_type_val) {
    $cnt = db_result(db_query("SELECT COUNT(*) AS cnt FROM {node} WHERE type = '%s'", $node_type_key));
    $node_types[$node_type_key] = $node_type_val . " ( " . $cnt . " )";
  }
  $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.'),
    '#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['storage_sitemap_id'] = array(
      '#type' => 'hidden',
      '#value' => $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;
}