Commit aacce5b7 authored by generalredneck's avatar generalredneck

[#1614234] Finishing Field Settings form and making it rebuild/delete index entries.

parent 28dfef61
......@@ -106,7 +106,6 @@ function views_natural_sort_rebuild_index_batch_set(array $entry_types = array()
* Batch API callback for rebuild_index.
*/
function views_natural_sort_rebuild_index($entry_type, &$context) {
dvm($entry_type);
// Alias sandbox for easier referencing.
$sandbox = &$context['sandbox'];
......
......@@ -7,25 +7,63 @@ function views_natural_sort_text_field_views_api() {
}
function views_natural_sort_text_field_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
$form['field']['views_natural_sort'] = array(
//TODO: Inform the user that this field is being used in views.
$form['field']['views_natural_sort_enable_sort'] = array(
'#type' => 'checkbox',
'#title' => t('Enable natural sorting.'),
'#description' => t('Selecting this option will process and index this field\'s value for natural sorting in views.'),
'#default_value' => 0,
'#default_value' => empty($form['#field']['views_natural_sort_enable_sort']) ? 0 : $form['#field']['views_natural_sort_enable_sort'],
);
$form['#submit'][] = 'views_natural_sort_text_field_form_field_ui_field_edit_form_alter_submit';
}
function views_natural_sort_text_field_views_natural_sort_get_rebuild_data() {
function views_natural_sort_text_field_form_field_ui_field_edit_form_alter_submit($form, $form_state) {
// Rebuild index for this field.
if($form_state['input']['field']['views_natural_sort_enable_sort'] != 1) {
//TODO: Revert views back to regular sort ASC & DESC.
db_delete('views_natural_sort')
->condition('field', $form['#field']['field_name'])
->execute();
}
else {
module_load_include('inc', 'views_natural_sort', 'views_natural_sort.admin');
views_natural_sort_rebuild_index_batch_set(views_natural_sort_text_field_views_natural_sort_get_entry_types(array($form['#field'])));
}
}
function views_natural_sort_text_field_views_natural_sort_get_entry_types($fields = array()) {
if (empty($fields)) {
$fields = views_natural_sort_text_field_get_configured_fields();
}
$entry_types = array();
foreach($fields as $field) {
$entry_types += views_natural_sort_text_field_get_entry_types_from_field($field);
}
return $entry_types;
}
function views_natural_sort_text_field_get_entry_types_from_field($field) {
$entry_types = array();
foreach($field['bundles'] as $entity_type => $bundles) {
$entry_types[] = array(
'entity_type' => $entity_type,
'field' => $field['field_name'],
);
}
return $entry_types;
}
function views_natural_sort_text_field_views_natural_sort_get_rebuild_data($entry_type) {
if (!in_array($entry_type,views_natural_sort_text_field_views_natural_sort_get_entry_types())) {
return array();
}
$field = field_info_field($entry_type['field']);
$data = array();
$configured_fields = views_natural_sort_text_field_get_configured_fields();
foreach ($configured_fields as $field) {
//TODO: in get_configured_fields() remove the entity types and bundles we don't want.
foreach ($field['bundles'] as $entity_type => $bundles) {
$entities = entity_load($entity_type);
foreach ($entities as $entity) {
//TODO: add = back in.
$data += _views_natural_sort_text_field_to_vns($entity_type, $entity, $field);
}
$entities = entity_load($entry_type['entity_type']);
foreach ($entities as $entity) {
$entries = _views_natural_sort_text_field_to_vns($entry_type['entity_type'], $entity, $field);
if (!empty($entries)) {
$data += $entries;
}
}
return $data;
......@@ -55,7 +93,8 @@ function views_natural_sort_text_field_get_configured_fields(){
foreach($all_fields as $field_name => $field) {
if ($field['module'] == 'text' &&
$field['storage']['type'] == 'field_sql_storage' &&
$field['columns']['value']['type'] == 'varchar') {
$field['columns']['value']['type'] == 'varchar' &&
$field['views_natural_sort_enable_sort']) {
$returned_fields[$field['id']] = $field;
}
}
......
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