Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
checklistapi
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
checklistapi
Commits
4ed3d7df
Commit
4ed3d7df
authored
May 15, 2012
by
Travis Carden
Browse files
Options
Downloads
Patches
Plain Diff
Changed checklistapi_sort_array() to return a value instead of operating on a reference.
parent
1595dca0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
checklistapi.module
+8
-4
8 additions, 4 deletions
checklistapi.module
with
8 additions
and
4 deletions
checklistapi.module
+
8
−
4
View file @
4ed3d7df
...
@@ -44,9 +44,9 @@ function checklistapi_get_checklist_info() {
...
@@ -44,9 +44,9 @@ function checklistapi_get_checklist_info() {
$checklists
=
&
drupal_static
(
__FUNCTION__
);
$checklists
=
&
drupal_static
(
__FUNCTION__
);
if
(
!
isset
(
$checklists
))
{
if
(
!
isset
(
$checklists
))
{
$checklists
=
module_invoke_all
(
'checklistapi_checklist_info'
);
$checklists
=
module_invoke_all
(
'checklistapi_checklist_info'
);
checklistapi_sort_array
(
$checklists
);
$checklists
=
checklistapi_sort_array
(
$checklists
);
drupal_alter
(
'checklistapi_checklist_info'
,
$checklists
);
drupal_alter
(
'checklistapi_checklist_info'
,
$checklists
);
checklistapi_sort_array
(
$checklists
);
$checklists
=
checklistapi_sort_array
(
$checklists
);
}
}
return
$checklists
;
return
$checklists
;
}
}
...
@@ -118,9 +118,12 @@ function checklistapi_permission() {
...
@@ -118,9 +118,12 @@ function checklistapi_permission() {
* A nested array of elements and properties such as the checklist definitions
* A nested array of elements and properties such as the checklist definitions
* returned by hook_checklistapi_checklist_info().
* returned by hook_checklistapi_checklist_info().
*
*
* @return array
* The input array sorted recursively by weight.
*
* @see checklistapi_get_checklist_info()
* @see checklistapi_get_checklist_info()
*/
*/
function
checklistapi_sort_array
(
array
&
$array
)
{
function
checklistapi_sort_array
(
array
$array
)
{
$child_keys
=
element_children
(
$array
);
$child_keys
=
element_children
(
$array
);
if
(
count
(
$child_keys
))
{
if
(
count
(
$child_keys
))
{
$incrementer
=
0
;
$incrementer
=
0
;
...
@@ -138,7 +141,7 @@ function checklistapi_sort_array(array &$array) {
...
@@ -138,7 +141,7 @@ function checklistapi_sort_array(array &$array) {
// function when its comparison callback finds two values equal.
// function when its comparison callback finds two values equal.
$children
[
$key
][
'#weight'
]
+=
(
$incrementer
++
/
1000
);
$children
[
$key
][
'#weight'
]
+=
(
$incrementer
++
/
1000
);
// Descend into child.
// Descend into child.
checklistapi_sort_array
(
$children
[
$key
]);
$children
[
$key
]
=
checklistapi_sort_array
(
$children
[
$key
]);
}
}
// Sort by #weight.
// Sort by #weight.
uasort
(
$children
,
'element_sort'
);
uasort
(
$children
,
'element_sort'
);
...
@@ -149,4 +152,5 @@ function checklistapi_sort_array(array &$array) {
...
@@ -149,4 +152,5 @@ function checklistapi_sort_array(array &$array) {
// Put children back in the main array.
// Put children back in the main array.
$array
+=
$children
;
$array
+=
$children
;
}
}
return
$array
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment