Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save orakili/2eb56343b00f3713891d68df0efa6688 to your computer and use it in GitHub Desktop.
Save orakili/2eb56343b00f3713891d68df0efa6688 to your computer and use it in GitHub Desktop.
Prevent php warnings when class is not set.
diff --git a/context.module b/context.module
index 5c0bd5c..5db5763 100644
--- a/context.module
+++ b/context.module
@@ -244,8 +244,10 @@ function context_preprocess_menu_link(&$variables) {
// - Do not add class twice on current page.
if (in_array($variables['element']['#href'], $reaction_menu_paths) && $variables['element']['#href'] != $_GET['q']) {
// Do not add the 'active' class twice in views tabs.
- if (!in_array('active', $variables['element']['#localized_options']['attributes']['class'])) {
- $variables['element']['#localized_options']['attributes']['class'][] = 'active';
+ if (!empty($variables['element']['#localized_options']['attributes']['class'])) {
+ if (!in_array('active', $variables['element']['#localized_options']['attributes']['class'])) {
+ $variables['element']['#localized_options']['attributes']['class'][] = 'active';
+ }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment