Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
While working on a way to allow translatable variables in Drupal I found that drupal_eval is directly using $conf instead of calling variable_get:
function drupal_eval($code) {
global $theme_path, $theme_info, $conf;
// Store current theme path.
$old_theme_path = $theme_path;
// Restore theme_path to the theme, as long as drupal_eval() executes,
// so code evaluated will not see the caller module as the current theme.
// If theme info is not initialized get the path from theme_default.
if (!isset($theme_info)) {
$theme_path = drupal_get_path('theme', $conf['theme_default']);
}
else {
$theme_path = dirname($theme_info->filename);
}
ob_start();
print eval('..breaks format..' . $code);
$output = ob_get_contents();
ob_end_clean();
// Recover original theme path.
$theme_path = $old_theme_path;
return $output;
}
I can't see any obvious reason for it - and any direct access to $conf makes future changes to $conf / variable_get / etc harder to do - wrappers provide most value if ALL access is done via those wrapper.
The attached patch changes this.
Comment | File | Size | Author |
---|---|---|---|
core.drupalEval.patch | 1 KB | Anonymous (not verified) | |
Comments
Comment #2
drupal_was_my_past CreditAttribution: drupal_was_my_past commentedWhile drupal_eval was renamed php_eval in 7.x, it's still calling a global $conf. Though I'm not sure if the issue of whether this is bad form or not is true, I can verify the issue.
Comment #3
drupal_was_my_past CreditAttribution: drupal_was_my_past commentedChanging to 8.x.
Comment #4
jameswoods CreditAttribution: jameswoods commentedI was going to work on this issue in 8.x, but the php_eval function in ore/modules/php/php.module doesn't seem to use global $conf anymore. It uses config('system.theme')->get('default').
I'm going to update the status to "needs review".
-James
Comment #5
swentel CreditAttribution: swentel commentedthe php module doesn't existing anymore in d8