Commit 446e2ea3 authored by gbyte.co's avatar gbyte.co

Some light UI implementation.

parent 9cc8e25d
content_types:
page:
priority: 0.5
content_types: []
home:
index: true
......@@ -9,5 +7,5 @@ home:
custom:
- contact:
path: contact
index: false
index: true
priority: 0.3
<?php
function simplesitemap_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == 'node_type_edit_form') {
// Setting defaults.
$index_content_checked = FALSE;
$priority = 0.5;
$content_types = \Drupal::config('simplesitemap.settings')->get('content_types');
if (isset($content_types[$form['type']['#default_value']]['index'])) {
$index_content_checked = $content_types[$form['type']['#default_value']]['index'] ? TRUE : FALSE;
if (isset($content_types[$form['type']['#default_value']]['priority']))
$priority = $content_types[$form['type']['#default_value']]['priority'];
}
$form['simplesitemap'] = array(
'#group' => 'additional_settings',
'#title' => 'Simple XML sitemap',
'#type' => 'details'
);
$form['simplesitemap']['simplesitemap_index_content'] = array(
'#type' => 'checkbox',
'#title' => 'Index content of this type',
'#default_value' => $index_content_checked,
);
$form['simplesitemap']['simplesitemap_priority'] = array(
'#type' => 'select',
'#title' => 'Priority',
'#default_value' => $priority,
'#description' => 'The priority nodes of this content type will have in the eyes of search engine bots.',
);
foreach(range(0, 10) as $value) {
$value = $value / 10;
$options[(string)$value] = (string)$value;
}
$form['simplesitemap']['simplesitemap_priority']['#options'] = $options;
$form['actions']['submit']['#submit'][] = 'simplesitemap_bundle_form_submit';
}
}
function simplesitemap_bundle_form_submit($form, &$form_state) {
$values = $form_state->getValues();
$config = \Drupal::service('config.factory')->getEditable('simplesitemap.settings');
$content_types = $config->get('content_types');
$content_types[$form['type']['#default_value']]['index'] = $values['simplesitemap_index_content'];
$content_types[$form['type']['#default_value']]['priority'] = $values['simplesitemap_priority'];
$config->set('content_types', $content_types)->save();
}
......@@ -41,25 +41,27 @@ class SimplesitemapController {
$output .= "<url><loc>" . $base_url . '/' . $page['path'] . "</loc><priority>" . $page['priority'] . "</priority></url>";
}
}
if (count($content_types) > 0) {
//todo: D8 entityQuery doesn't seem to take multiple OR conditions, that's why that ugly db_select.
/* $query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', array_keys($content_types));
$nids = $query->execute();*/
$query = db_select('node_field_data', 'n')
->fields('n', array('nid', 'type'))
->condition('status', 1);
$db_or = db_or();
foreach($content_types as $machine_name => $options) {
$db_or->condition('type', $machine_name);
}
$query->condition($db_or);
$nids = $query->execute()->fetchAllAssoc('nid');
//todo: D8 entityQuery doesn't seem to take multiple OR conditions, that's why that ugly db_select.
/* $query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', array_keys($content_types));
$nids = $query->execute();*/
$query = db_select('node_field_data', 'n')
->fields('n', array('nid', 'type'))
->condition('status', 1);
$db_or = db_or();
foreach($content_types as $machine_name => $options) {
$db_or->condition('type', $machine_name);
}
$query->condition($db_or);
$nids = $query->execute()->fetchAllAssoc('nid');
foreach($nids as $nid => $node) {
$link_url = Url::fromRoute('entity.node.canonical', array('node' => $nid), array('absolute' => TRUE));
$output .= "<url><loc>" . $link_url->toString() . "</loc><priority>" . $content_types[$node->type]['priority'] . "</priority></url>";
foreach($nids as $nid => $node) {
$link_url = Url::fromRoute('entity.node.canonical', array('node' => $nid), array('absolute' => TRUE));
$output .= "<url><loc>" . $link_url->toString() . "</loc><priority>" . $content_types[$node->type]['priority'] . "</priority></url>";
}
}
$output .= "</urlset>";
......
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