Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
views_natural_sort
Commits
69b9a291
Commit
69b9a291
authored
Jan 30, 2013
by
generalredneck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[
#1614234
] Finishing Field Settings form and making it rebuild/delete index entries.
parent
28dfef61
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
14 deletions
+54
-14
views_natural_sort.admin.inc
views_natural_sort.admin.inc
+2
-1
views_natural_sort_text_field.module
views_natural_sort_text_field.module
+52
-13
No files found.
views_natural_sort.admin.inc
View file @
69b9a291
...
...
@@ -87,6 +87,7 @@ function views_natural_sort_rebuild_index_batch_set(array $entry_types = array()
if
(
empty
(
$entry_types
))
{
$entry_types
=
module_invoke_all
(
'views_natural_sort_get_entry_types'
);
}
dvm
(
$entry_types
);
$operations
=
array
();
foreach
(
$entry_types
as
$entry_type
)
{
...
...
@@ -106,13 +107,13 @@ 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'
];
// Hook for modules to implement and return data that views_natural_sort can
// store as an index for that module's entries.
$index_entries
=
module_invoke_all
(
'views_natural_sort_get_rebuild_data'
,
$entry_type
);
dvm
(
$index_entries
);
//TODO: this seems like it has the possiblity to produce unused data.
// Consider a delete of some sort.
...
...
views_natural_sort_text_field.module
View file @
69b9a291
...
...
@@ -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
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment