Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443488
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3443488
Commits
32dd3b46
Commit
32dd3b46
authored
15 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
#660856
by effulgentsia: Optimize template_preprocess().
parent
c675d4f9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
includes/theme.inc
+44
-23
44 additions, 23 deletions
includes/theme.inc
with
44 additions
and
23 deletions
includes/theme.inc
+
44
−
23
View file @
32dd3b46
...
...
@@ -2252,32 +2252,53 @@ function template_preprocess(&$variables, $hook) {
// Initialize html class attribute for the current hook.
$variables
[
'classes_array'
]
=
array
(
drupal_html_class
(
$hook
));
// Initialize attributes for the top-level template entity and its title and
// content.
$variables
[
'attributes_array'
]
=
array
();
$variables
[
'title_attributes_array'
]
=
array
();
$variables
[
'content_attributes_array'
]
=
array
();
// Initialize 'title_prefix' and 'title_suffix' renderable arrays.
$variables
[
'title_prefix'
]
=
array
();
$variables
[
'title_suffix'
]
=
array
();
// Set default variables that depend on the database.
$variables
[
'is_admin'
]
=
FALSE
;
$variables
[
'is_front'
]
=
FALSE
;
$variables
[
'logged_in'
]
=
FALSE
;
if
(
$variables
[
'db_is_active'
]
=
!
defined
(
'MAINTENANCE_MODE'
)
&&
db_is_active
())
{
// Check for administrators.
if
(
user_access
(
'access administration pages'
))
{
$variables
[
'is_admin'
]
=
TRUE
;
}
// Flag front page status.
// Merge in variables that don't depend on hook and don't change during a
// single page request.
// Use the advanced drupal_static() pattern, since this is called very often.
static
$drupal_static_fast
;
if
(
!
isset
(
$drupal_static_fast
))
{
$drupal_static_fast
[
'default_variables'
]
=
&
drupal_static
(
__FUNCTION__
);
}
$default_variables
=
&
$drupal_static_fast
[
'default_variables'
];
// Global $user object shouldn't change during a page request once rendering
// has started, but if there's an edge case where it does, re-fetch the
// variables appropriate for the new user.
if
(
!
isset
(
$default_variables
)
||
(
$user
!==
$default_variables
[
'user'
]))
{
$default_variables
=
_template_preprocess_default_variables
();
}
$variables
+=
$default_variables
;
}
/**
* Returns hook-independant variables to template_preprocess().
*/
function
_template_preprocess_default_variables
()
{
global
$user
;
// Variables that don't depend on a database connection.
$variables
=
array
(
'attributes_array'
=>
array
(),
'title_attributes_array'
=>
array
(),
'content_attributes_array'
=>
array
(),
'title_prefix'
=>
array
(),
'title_suffix'
=>
array
(),
'user'
=>
$user
,
'db_is_active'
=>
!
defined
(
'MAINTENANCE_MODE'
)
&&
db_is_active
(),
);
// Variables that depend on a database connection.
if
(
$variables
[
'db_is_active'
])
{
$variables
[
'is_admin'
]
=
user_access
(
'access administration pages'
);
$variables
[
'is_front'
]
=
drupal_is_front_page
();
// Tell all templates by which kind of user they're viewed.
$variables
[
'logged_in'
]
=
(
$user
->
uid
>
0
);
// Provide user object to all templates
$variables
[
'user'
]
=
$user
;
}
else
{
$variables
[
'is_admin'
]
=
FALSE
;
$variables
[
'is_front'
]
=
FALSE
;
$variables
[
'logged_in'
]
=
FALSE
;
}
return
$variables
;
}
/**
...
...
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