|
27 | 27 | /**
|
28 | 28 | * @} End of 'defgroup examples'.
|
29 | 29 | */
|
| 30 | + |
| 31 | +/** |
| 32 | + * Implements hook_toolbar(). |
| 33 | + */ |
| 34 | +function examples_toolbar() { |
| 35 | + // First, build an array of all example modules and their "root" path. |
| 36 | + // We resort to this hard-coded way so as not to muck up each example. |
| 37 | + $examples = array( |
| 38 | + 'block_example' => 'examples/block_example', |
| 39 | + 'cache_example' => 'examples/cache_example', |
| 40 | + 'config_entity_example' => 'examples/config_entity_example', |
| 41 | + 'content_entity_example' => 'content_entity_example_contact/list', |
| 42 | + 'dbtng_example' => 'examples/dbtng_example', |
| 43 | + 'email_example' => 'examples/email_example', |
| 44 | + 'field_example' => 'examples/field_example', |
| 45 | + 'form_example' => 'examples/form_example', |
| 46 | + 'js_example' => 'examples/js_example', |
| 47 | + 'node_type_example' => 'examples/node_type_example', |
| 48 | + 'page_example' => 'examples/page_example', |
| 49 | + 'phpunit_example' => 'examples/phpunit_example', |
| 50 | + 'simpletest_example' => 'examples/simpletest_example', |
| 51 | + 'tour_example' => 'examples/tour_example', |
| 52 | + ); |
| 53 | + |
| 54 | + // Build a list of links for the menu. |
| 55 | + $links = array(); |
| 56 | + foreach ($examples as $name => $href) { |
| 57 | + // Get the module info (title, description) from Drupal. |
| 58 | + $info = system_get_info('module', $name); |
| 59 | + |
| 60 | + // If there's no info, the example isn't enabled, so don't display it. |
| 61 | + if (!empty($info)) { |
| 62 | + $links[$name] = array( |
| 63 | + 'title' => t($info['name']), |
| 64 | + 'href' => $href, |
| 65 | + 'html' => TRUE, |
| 66 | + 'attributes' => array( |
| 67 | + 'title' => t($info['description']), |
| 68 | + ), |
| 69 | + ); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + // Add a link to enable all examples. |
| 74 | + $links['enable_examples'] = array( |
| 75 | + 'title' => t('Enable Examples'), |
| 76 | + 'href' => 'admin/modules', |
| 77 | + 'html' => TRUE, |
| 78 | + 'attributes' => array( |
| 79 | + 'title' => t('Enable more examples in on the Extend page.'), |
| 80 | + ), |
| 81 | + 'fragment' => 'edit-modules-example-modules', |
| 82 | + ); |
| 83 | + |
| 84 | + // Create the examples toolbar render array. |
| 85 | + $items['examples'] = array( |
| 86 | + '#type' => 'toolbar_item', |
| 87 | + 'tab' => array( |
| 88 | + '#type' => 'link', |
| 89 | + '#title' => t('Examples'), |
| 90 | + '#href' => 'examples', |
| 91 | + '#attributes' => array( |
| 92 | + 'title' => t('Developer Examples'), |
| 93 | + 'class' => array('toolbar-icon', 'toolbar-icon-examples'), |
| 94 | + ), |
| 95 | + ), |
| 96 | + 'tray' => array( |
| 97 | + '#heading' => t('Developer Examples'), |
| 98 | + 'shortcuts' => array( |
| 99 | + '#theme' => 'links__toolbar_shortcuts', |
| 100 | + '#links' => $links, |
| 101 | + '#attributes' => array( |
| 102 | + 'class' => array('menu'), |
| 103 | + ), |
| 104 | + ), |
| 105 | + ), |
| 106 | + '#weight' => 99, |
| 107 | + '#attached' => array( |
| 108 | + 'library' => array( |
| 109 | + 'examples/examples.icons', |
| 110 | + ), |
| 111 | + ), |
| 112 | + ); |
| 113 | + |
| 114 | + return $items; |
| 115 | +} |
0 commit comments