Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
V
views_natural_sort
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
views_natural_sort
Commits
aacce5b7
Commit
aacce5b7
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
52 additions
and
14 deletions
+52
-14
views_natural_sort.admin.inc
views_natural_sort.admin.inc
+0
-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 @
aacce5b7
...
...
@@ -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'
];
...
...
views_natural_sort_text_field.module
View file @
aacce5b7
...
...
@@ -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