Commit 96c2cce6 authored by generalredneck's avatar generalredneck

Finishing up Configuration Form.

parent daa50e7f
...@@ -23,7 +23,7 @@ class ConfigurationForm extends ConfigFormBase { ...@@ -23,7 +23,7 @@ class ConfigurationForm extends ConfigFormBase {
*/ */
protected function getEditableConfigNames() { protected function getEditableConfigNames() {
return [ return [
'view_natural_sort.settings', 'views_natural_sort.settings',
]; ];
} }
...@@ -64,11 +64,9 @@ class ConfigurationForm extends ConfigFormBase { ...@@ -64,11 +64,9 @@ class ConfigurationForm extends ConfigFormBase {
'#default_value' => $config->get('rebuild_items_per_batch'), '#default_value' => $config->get('rebuild_items_per_batch'),
'#min' => 0, '#min' => 0,
'#description' => $this->t('The number of items a batch process will work through at a given time. Raising this number will make the batch go quicker, however, raising it too high can cause timeouts and/or memory limit errors.'), '#description' => $this->t('The number of items a batch process will work through at a given time. Raising this number will make the batch go quicker, however, raising it too high can cause timeouts and/or memory limit errors.'),
'#element_validate' => array('element_validate_integer_positive'),
); );
$form = parent::buildForm($form, $form_state);
$form['rebuild'] = [ $form['rebuild'] = [
'#type' => 'fieldset', '#type' => 'details',
'#title' => $this->t('Incase of Emergency'), '#title' => $this->t('Incase of Emergency'),
'#collapsible' => TRUE, '#collapsible' => TRUE,
'#collapsed' => TRUE, '#collapsed' => TRUE,
...@@ -77,10 +75,10 @@ class ConfigurationForm extends ConfigFormBase { ...@@ -77,10 +75,10 @@ class ConfigurationForm extends ConfigFormBase {
'#type' => 'submit', '#type' => 'submit',
'#description' => 'Incase of an emergency.', '#description' => 'Incase of an emergency.',
'#value' => $this->t('Rebuild Index'), '#value' => $this->t('Rebuild Index'),
'#submit' => array('submitFormReindexOnly'), '#submit' => [[$this, 'submitFormReindexOnly']],
], ],
]; ];
return $form; return parent::buildForm($form, $form_state);
} }
/** /**
......
views_natural_sort.settings:
path: 'admin/structure/views/settings/views_natural_sort'
base_route: views_ui.settings_basic
defaults:
_form: '\Drupal\views_natural_sort\Form\ConfigurationForm'
_title: 'Views Natural Sort Configuration'
requirements:
_permission: 'administer views'
<?php
// $Id$
/**
* @file
* Callbacks for managing Views Natural Sort.
*/
/**
* Form callback for Views Natural Sort settings page..
*
* Allows rebuilding index but should also allow things like limiting what node
* types are indexed and cck text field index options.
*/
function views_natural_sort_settings_form() {
$form = array();
$form['rebuild'] = array(
'#type' => 'submit',
'#value' => t('Rebuild title index'),
'#submit' => array('views_natural_sort_rebuild_index_submit'),
);
return $form;
}
/**
* Submit handler that triggers the rebuild_index batch.
*/
function views_natural_sort_rebuild_index_submit() {
$batch = array(
'operations' => array(
array('views_natural_sort_rebuild_index', array()),
),
'finished' => 'views_natural_sort_rebuild_index_finished',
'file' => drupal_get_path('module', 'views_natural_sort') . '/views_natural_sort.admin.inc',
);
batch_set($batch);
}
/**
* Batch API callback for rebuild_index.
*/
function views_natural_sort_rebuild_index(&$context) {
// Alias sandbox for easier referencing.
$sandbox = &$context['sandbox'];
// Initialize our context.
if (!isset($sandbox['max'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = db_result(db_query('SELECT MAX(nid) FROM {node}'));
$sandbox['total'] = db_result(db_query('SELECT COUNT(nid) FROM {node} WHERE nid < %d', $sandbox['max']));
$sandbox['current'] = 0;
$context['results']['nodes'] = 0;
}
$results = db_query_range('SELECT nid, title FROM {node} WHERE nid > %d AND nid < %d', $sandbox['current'], $sandbox['max'], 0, 10);
$title = '';
while($row = db_fetch_object($results)) {
_views_natural_sort_store_node($row);
++$sandbox['progress'];
$sandbox['current'] = $row->nid;
$title = $row->title;
++$context['results']['nodes'];
}
$context['message'] = t('Processing node %title', array('%title' => $title));
$context['finished'] = $sandbox['progress'] / $sandbox['total'];
}
/**
* Finished callback for rebuild_index batch.
*/
function views_natural_sort_rebuild_index_finished($success, $results, $operations) {
if ($success) {
drupal_set_message(t('Index update has completed.'));
drupal_set_message(t('Indexed %count.', array(
'%count' => format_plural($results['nodes'], '1 node', '@count nodes'),
)));
}
}
...@@ -3,6 +3,6 @@ type: module ...@@ -3,6 +3,6 @@ type: module
description: Sort results naturaly on a node's title skipping articles like "the" and "a." description: Sort results naturaly on a node's title skipping articles like "the" and "a."
core: 8.x core: 8.x
package: Views package: Views
configure: view_natural_sort.settings configure: views_natural_sort.settings
dependencies: dependencies:
- views - views
views_natural_sort.settings_tab:
route_name: views_natural_sort.settings
weight: 100
title: Natural Sort
parent_id: views_ui.settings_tab
your_module.admin_settings: views_natural_sort.settings:
path: 'admin/structure/views/settings/views_natural_sort' path: 'admin/structure/views/settings/views_natural_sort'
defaults: defaults:
_form: '\Drupal\views_natural_sort\Form\ConfigurationForm' _form: '\Drupal\views_natural_sort\Form\ConfigurationForm'
......
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