Bad code in styles theme preprocessor

Created on 18 July 2011, almost 14 years ago
Updated 11 June 2025, 2 days ago

Line 27 of styles.theme.inc is referencing $variables['instance'] as an object shortly before checking $variables['instance'] to determine whether to render anything. This line should really be moved inside the if statement to prevent problems with accessing a non object when instance is not set correctly.

function template_preprocess_styles(&$variables) {
  // If we have a Styles object instance already, then honor that.
  // Otherwise, we'll build a new Styles object instance from our settings.
  $variables['instance'] = $variables['instance'] ? $variables['instance'] : styles_instance($variables);

  // Add the style name to the wrapper's classes array.
  $variables['instance']->arrayPush('classes', $variables['style_name']);

  if ($variables['instance']) {
    // Prefix and suffix are for the wrapper, such as div or span.
    $variables['prefix'] = $variables['instance']->getPrefix();
    $variables['suffix'] = $variables['instance']->getSuffix();

    // Render the output for the template file.
    $variables['output'] = $variables['instance']->display(TRUE);
  }
  else {
    // We have no instance, thus nothing to output.
    $variables['output'] = '';
  }
}
πŸ› Bug report
Status

Closed: outdated

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom jamiecuthill

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    Thank you for your contributions to this issue. As Drupal 7 has reached its End of Life and is no longer supported, we are closing this issue. We encourage you to upgrade to a supported version of Drupal.

Production build 0.71.5 2024