Commit 0f4d9462 authored by andrei.dincu's avatar andrei.dincu

Issue #2249723 by andrei.dincu: Move xmlsitemap_add_form_link_options() to xmlsitemap.module

parent 9344fd80
......@@ -648,134 +648,6 @@ function xmlsitemap_link_bundle_settings_form(array $form, array &$form_state, a
return $form;
}
/**
* Add a link's XML sitemap options to the link's form.
*
* @todo Add changefreq overridability.
*/
function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
$info = xmlsitemap_get_link_info($entity, TRUE);
/* 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,
);
$currentUser = \Drupal::currentUser();
$form['xmlsitemap'] = array(
'#type' => 'details',
'#tree' => TRUE,
'#title' => t('XML sitemap'),
'#collapsible' => TRUE,
'#collapsed' => !$link['status_override'] && !$link['priority_override'],
'#access' => $currentUser->hasPermission('administer 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'],
);
$form['actions']['submit']['#submit'][] = 'xmlsitemap_process_form_link_options';
// Other persistent fields.
//$form['xmlsitemap']['lastmod'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['lastmod'],
//);
//$form['xmlsitemap']['changefreq'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['changefreq'],
//);
//$form['xmlsitemap']['changecount'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['changecount'],
//);
}
/**
* Get a list of priority options.
*
......
......@@ -1370,6 +1370,135 @@ function xmlsitemap_restore_user() {
return xmlsitemap_switch_user();
}
/**
* Add a link's XML sitemap options to the link's form.
*
* @todo Add changefreq overridability.
*/
function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
$info = xmlsitemap_get_link_info($entity, TRUE);
/* 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,
);
$currentUser = \Drupal::currentUser();
$form['xmlsitemap'] = array(
'#type' => 'details',
'#tree' => TRUE,
'#title' => t('XML sitemap'),
'#collapsible' => TRUE,
'#collapsed' => !$link['status_override'] && !$link['priority_override'],
'#access' => $currentUser->hasPermission('administer 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'],
);
$form['actions']['submit']['#submit'][] = 'xmlsitemap_process_form_link_options';
// Other persistent fields.
//$form['xmlsitemap']['lastmod'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['lastmod'],
//);
//$form['xmlsitemap']['changefreq'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['changefreq'],
//);
//$form['xmlsitemap']['changecount'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['changecount'],
//);
}
/**
* Submit callback for the entity form to save.
*/
......@@ -1711,7 +1840,6 @@ function xmlsitemap_form_alter(array &$form, array &$form_state) {
return;
}
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_form_link_options($form, $entity_type, $bundle, $entity->id());
$form['xmlsitemap']['#weight'] = 100;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment