By hpn


2011-11-17 16:57:57 8 Comments

I searched for links__system_main_menu, but just find usages of this theme. Where is it defined?

2 comments

@tecjam 2011-11-17 20:38:10

theme_links__system_main_menu() is not currently defined from Drupal, but Drupal will use MYTHEME_links__system_main_menu(), if you define it in your theme.

function MYTHEME_links__system_main_menu($variables) {
  $html = "<div>\n";
  $html .= "  <ul>\n"; 

  foreach ($variables['links'] as $link) {
    $html .= "<li>".l($link['title'], $link['path'], $link)."</li>";
  }

  $html .= "  </ul>\n";
  $html .= "</div>\n";

  return $html;
}

You can find some more info on http://drupal.org/node/1033442#comment-5076932.

@keithm 2011-11-18 12:25:14

Drupal 7 core doesn't actually define this function.

links__system_main_menu is a theme hook pattern of the form [base hook]__[context]. When links are themed with theme('links__system_main_menu', $vars), theme() will search for and use theme_links__system_main_menu() if it has been defined. If not, it will use theme_links().

See theme() for the official documentation of this behavior. Chapter 3 of Drupal 7 Module Development does an excellent job of explaining this and provides several examples.

BTW, the same principle applies to template files. If, for example, we call theme('node__article__1', $vars), theme() will search for a node--article--1.tpl.php file, and then for node--article.tpl.php, finally falling back to node.tpl.php if neither of them are defined.

Related Questions

Sponsored Content

2 Answered Questions

[SOLVED] How to use preprocess function for custom templates defined in hook_theme?

  • 2015-08-04 05:38:37
  • Sugandh Khanna
  • 1460 View
  • 0 Score
  • 2 Answer
  • Tags:   theming

1 Answered Questions

[SOLVED] Where is my stylesheet located?

  • 2017-10-05 08:03:55
  • Christian Gedge
  • 25 View
  • 1 Score
  • 1 Answer
  • Tags:   theming

2 Answered Questions

[SOLVED] Where is links__node__node() defined?

  • 2011-12-01 09:57:43
  • kristian nissen
  • 524 View
  • 3 Score
  • 2 Answer
  • Tags:   theming navigation

1 Answered Questions

1 Answered Questions

[SOLVED] Where is the class "placeholder" defined?

  • 2013-09-30 21:13:02
  • Matt
  • 673 View
  • 1 Score
  • 1 Answer
  • Tags:   theming

1 Answered Questions

[SOLVED] Where is Twig service defined?

  • 2013-09-22 08:22:02
  • Andy Truong
  • 363 View
  • 3 Score
  • 1 Answer
  • Tags:   8 theming

1 Answered Questions

[SOLVED] Where do I find the translation overview?

  • 2012-09-22 20:01:20
  • Jan Werkhoven
  • 169 View
  • 0 Score
  • 1 Answer
  • Tags:   7 i18n-l10n

1 Answered Questions

[SOLVED] Where are the main menu links created?

  • 2012-07-24 14:18:55
  • Digital fire
  • 245 View
  • 1 Score
  • 1 Answer
  • Tags:   7 routes

Sponsored Content