You are here

function simplesitemap_form_alter in Simple XML sitemap 8

Implements hook_form_alter.

Adds sitemap settings to entity types that are supported via plugins.

File

./simplesitemap.module, line 15
Main module file containing hooks.

Code

function simplesitemap_form_alter(&$form, $form_state, $form_id) {
  $sitemap_form_entity_data = Simplesitemap::get_sitemap_form_entity_data($form_state, $form_id);
  if (empty($sitemap_form_entity_data)) {
    return;
  }
  $entity_type_id = $sitemap_form_entity_data['entity_type_id'];
  $bundle_name = $sitemap_form_entity_data['bundle_name'];
  $sitemap = new Simplesitemap();

  // Get current entity type sitemap settings.
  $entity_types = $sitemap
    ->get_config('entity_types');
  $form['simplesitemap'] = array(
    '#type' => 'details',
    '#group' => 'additional_settings',
    '#title' => t('Simple XML sitemap'),
  );

  // Attach some js magic to forms.
  // Only attach fieldset summary js to 'additional settings' vertical tabs.
  $form['simplesitemap']['#attached']['library'][] = 'simplesitemap/form';
  if (isset($form['additional_settings'])) {
    $form['simplesitemap']['#attached']['library'][] = 'simplesitemap/fieldsetSummaries';
  }
  $index_content_checked = isset($entity_types[$entity_type_id][$bundle_name]['index']) ? $entity_types[$entity_type_id][$bundle_name]['index'] : FALSE;
  $form['simplesitemap']['simplesitemap_index_content'] = array(
    '#type' => 'checkbox',
    '#title' => t('Index content of this type'),
    '#default_value' => $index_content_checked,
  );
  $priority = isset($entity_types[$entity_type_id][$bundle_name]['priority']) ? $entity_types[$entity_type_id][$bundle_name]['priority'] : SitemapGenerator::PRIORITY_DEFAULT;
  $form['simplesitemap']['simplesitemap_priority'] = array(
    '#type' => 'select',
    '#title' => t('Priority'),
    '#description' => t('The priority entities of this bundle will have in the eyes of search engine bots.'),
    '#options' => SitemapGenerator::get_priority_select_values(),
    '#default_value' => $priority,
  );
  $form['simplesitemap']['simplesitemap_regenerate_now'] = array(
    '#type' => 'checkbox',
    '#title' => t('Regenerate sitemap after hitting Save'),
    '#description' => t('This setting will regenerate the whole sitemap including the above changes.<br/>Otherwise the sitemap will be rebuilt on next cron run.'),
    '#default_value' => FALSE,
  );
  $form['#simplesitemap']['entity_type_id'] = $entity_type_id;
  $form['#simplesitemap']['bundle_name'] = $bundle_name;

  // Add submission handler.
  if (isset($form['actions']['submit']['#submit'])) {
    $form['actions']['submit']['#submit'][] = 'simplesitemap_entity_form_submit';
  }
  else {

    // Fix for account page which rendered other submit handlers not usable.
    $form['#submit'][] = 'simplesitemap_entity_form_submit';
  }
}