Commit bfc9734c authored by generalredneck's avatar generalredneck

[#1614234] Enabling field index creation and update in views_natural_sort table.

parent 062b8731
......@@ -57,6 +57,11 @@ function views_natural_sort_menu() {
return $items;
}
function views_natural_sort_store_multiple(array $index_entries) {
foreach($index_entries as $entry) {
views_natural_sort_store($entry);
}
}
function views_natural_sort_store($index_entry) {
//This should take a formatted object and store it into the views_natural_sort table.
return db_merge('views_natural_sort')
......@@ -91,7 +96,7 @@ function views_natural_sort_remove($index_entry) {
*/
function views_natural_sort_views_api() {
return array(
'api' => 2.0,
'api' => 3.0,
);
}
......
......@@ -14,3 +14,71 @@ function views_natural_sort_text_field_form_field_ui_field_edit_form_alter(&$for
'#default_value' => 0,
);
}
function views_natural_sort_text_field_views_natural_sort_get_rebuild_data() {
$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);
}
}
}
return $data;
}
function views_natural_sort_text_field_field_attach_insert($entity_type, $entity) {
$configured_fields = views_natural_sort_text_field_get_configured_fields();
foreach ($configured_fields as $field) {
if (in_array($entity_type, array_keys($field['bundles']))){
_views_natural_sort_text_field_store($entity_type, $entity, $field);
}
}
}
function views_natural_sort_text_field_field_attach_update($entity_type, $entity) {
$configured_fields = views_natural_sort_text_field_get_configured_fields();
foreach ($configured_fields as $field) {
if (in_array($entity_type, array_keys($field['bundles']))){
_views_natural_sort_text_field_store($entity_type, $entity, $field);
}
}
}
function views_natural_sort_text_field_get_configured_fields(){
$all_fields = field_info_fields();
$returned_fields = array();
foreach($all_fields as $field_name => $field) {
if ($field['module'] == 'text' &&
$field['storage']['type'] == 'field_sql_storage' &&
$field['columns']['value']['type'] == 'varchar') {
$returned_fields[$field['id']] = $field;
}
}
return $returned_fields;
}
function _views_natural_sort_text_field_store($entity_type, $entity, $field) {
views_natural_sort_store_multiple(_views_natural_sort_text_field_to_vns($entity_type, $entity, $field));
}
function _views_natural_sort_text_field_to_vns($entity_type, $entity, $field) {
$entity_info = entity_get_info($entity_type);
$entity_id_property = $entity_info['entity keys']['id'];
$field_name = $field['field_name'];
//TODO: add support for Field Language
$entries = array();
foreach(field_get_items($entity_type, $entity, $field_name) as $delta => $row) {
$entries[] = array(
'eid' => $entity->$entity_id_property,
'entity_type' => $entity_type,
'field' => $field_name,
'delta' => $delta,
'content' => $row['value']
);
}
return $entries;
}
......@@ -2,10 +2,9 @@
function views_natural_sort_text_field_field_views_data_alter(&$data, $field, $module) {
// TODO: check to see if field is "registered" to be sort naturally.
if ($module != 'text' || $field['storage']['type'] != 'field_sql_storage' || $field['columns']['value']['type'] != 'varchar') {
if (!in_array($field['id'], array_keys(views_natural_sort_text_field_get_configured_fields()))) {
return;
}
$field_table = _field_sql_storage_tablename($field);
$data[$field_table][$field['field_name'] . '_value']['sort']['handler'] = 'views_natural_sort_handler_sort_text_field';
dvm($data[$field_table]);
}
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