function xmlsitemap_add_form_link_options in XML sitemap 7.2
Same name and namespace in other branches
- 8 xmlsitemap.module \xmlsitemap_add_form_link_options()
- 6.2 xmlsitemap.admin.inc \xmlsitemap_add_form_link_options()
- 2.x xmlsitemap.module \xmlsitemap_add_form_link_options()
Add a link's XML sitemap options to the link's form.
@todo Add changefreq overridability.
4 calls to xmlsitemap_add_form_link_options()
- xmlsitemap_menu_form_menu_edit_item_alter in xmlsitemap_menu/
xmlsitemap_menu.module - Implements hook_form_FORM_ID_alter().
- xmlsitemap_node_form_node_form_alter in xmlsitemap_node/
xmlsitemap_node.module - Implements hook_form_alter().
- xmlsitemap_taxonomy_form_taxonomy_form_term_alter in xmlsitemap_taxonomy/
xmlsitemap_taxonomy.module - Implements hook_form_FORM_ID_alter().
- xmlsitemap_user_form_user_profile_form_alter in xmlsitemap_user/
xmlsitemap_user.module - Implements hook_form_FORM_ID_alter().
File
- ./
xmlsitemap.admin.inc, line 736 - Administrative page callbacks for the xmlsitemap module.
Code
function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
$info = xmlsitemap_get_link_info($entity);
if (!$info || empty($info['bundles'][$bundle])) {
return;
}
if (!($link = xmlsitemap_link_load($entity, $id))) {
$link = array();
}
$bundle_info = xmlsitemap_link_bundle_load($entity, $bundle);
$link += array(
'access' => 1,
'status' => $bundle_info['status'],
'status_default' => $bundle_info['status'],
'status_override' => 0,
'priority' => $bundle_info['priority'],
'priority_default' => $bundle_info['priority'],
'priority_override' => 0,
);
$form['xmlsitemap'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('XML sitemap'),
'#collapsible' => TRUE,
'#collapsed' => !$link['status_override'] && !$link['priority_override'],
'#access' => user_access('administer xmlsitemap') || user_access('use xmlsitemap') || xmlsitemap_link_bundle_access($bundle_info),
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(
'vertical-tabs' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.js',
),
),
);
// Hack to remove fieldset summary if Vertical tabs is not enabled.
if (!isset($form['additional_settings'])) {
unset($form['xmlsitemap']['#attached']['js']['vertical-tabs']);
}
if (xmlsitemap_link_bundle_access($bundle_info) && ($path = xmlsitemap_get_bundle_path($entity, $bundle))) {
$form['xmlsitemap']['description'] = array(
'#prefix' => '<div class="description">',
'#suffix' => '</div>',
'#markup' => t('The default XML sitemap settings for this @bundle can be changed <a href="@link-type">here</a>.', array(
'@bundle' => drupal_strtolower($info['bundle label']),
'@link-type' => url($path, array(
'query' => drupal_get_destination(),
)),
)),
);
}
// Show a warning if the link is not accessible and will not be included in
// the sitemap.
if ($id && !$link['access']) {
$form['xmlsitemap']['warning'] = array(
'#type' => 'markup',
'#prefix' => '<p><strong>',
'#suffix' => '</strong></p>',
'#value' => 'This item is not currently visible to anonymous users, so it will not be included in the sitemap.',
);
}
// Status field (inclusion/exclusion)
$form['xmlsitemap']['status'] = array(
'#type' => 'select',
'#title' => t('Inclusion'),
'#options' => xmlsitemap_get_status_options($link['status_default']),
'#default_value' => $link['status_override'] ? $link['status'] : 'default',
);
$form['xmlsitemap']['status_default'] = array(
'#type' => 'value',
'#value' => $link['status_default'],
);
$form['xmlsitemap']['status_override'] = array(
'#type' => 'value',
'#value' => $link['status_override'],
);
// Priority field.
$form['xmlsitemap']['priority'] = array(
'#type' => 'select',
'#title' => t('Priority'),
'#options' => xmlsitemap_get_priority_options($link['priority_default']),
'#default_value' => $link['priority_override'] ? number_format($link['priority'], 1) : 'default',
'#description' => t('The priority of this URL relative to other URLs on your site.'),
'#states' => array(
'invisible' => array(
'select[name="xmlsitemap[status]"]' => array(
'value' => '0',
),
),
),
);
if (!$link['status_default']) {
// If the default status is excluded, add a visible state on the include
// override option.
$form['xmlsitemap']['priority']['#states']['visible'] = array(
'select[name="xmlsitemap[status]"]' => array(
'value' => '1',
),
);
}
$form['xmlsitemap']['priority_default'] = array(
'#type' => 'value',
'#value' => $link['priority_default'],
);
$form['xmlsitemap']['priority_override'] = array(
'#type' => 'value',
'#value' => $link['priority_override'],
);
// Add the submit handler to adjust the default values if selected.
$form += array(
'#submit' => array(),
);
if (!in_array('xmlsitemap_process_form_link_options', $form['#submit'])) {
array_unshift($form['#submit'], 'xmlsitemap_process_form_link_options');
}
}