Skip to content

Commit ea1dc41

Browse files
Mile23paul-m
Mile23
authored andcommitted
Issue #2318729 by socketwench, Mile23: Added Create a global examples toolbar.
1 parent 14abc3c commit ea1dc41

19 files changed

+207
-3
lines changed

block_example/block_example.info.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ package: Example modules
55
core: 8.x
66
dependencies:
77
- block
8+
- examples

cache_example/cache_example.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ description: 'An example outlining how to use Cache API.'
33
package: Example modules
44
core: 8.x
55
type: module
6+
dependencies:
7+
- examples

config_entity_example/config_entity_example.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ type: module
33
description: 'An example module showing how to create a config entity type.'
44
package: Example modules
55
core: 8.x
6+
dependencies:
7+
- examples

content_entity_example/content_entity_example.info.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ core: 8.x
77
dependencies:
88
- options
99
- entity_reference
10+
- examples

css/examples.icons.css

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @file
3+
* Styling for the user module icons.
4+
*/
5+
6+
/**
7+
* Toolbar tab icon.
8+
*/
9+
.toolbar-bar .toolbar-icon-examples:before {
10+
background-image: url(../images/examples.svg);
11+
}
12+
.toolbar-bar .toolbar-icon-examples:active:before,
13+
.toolbar-bar .toolbar-icon-examples.active:before {
14+
background-image: url(../images/examples.svg);
15+
}

dbtng_example/dbtng_example.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ type: module
33
description: 'An example module showing how use the database API: DBTNG.'
44
package: Example modules
55
core: 8.x
6+
dependencies:
7+
- examples

email_example/email_example.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ description: An example module that sends and alter drupal generated email messa
44
package: Example modules
55
version: 8.x-1.x
66
core: 8.x
7+
dependencies:
8+
- examples

examples.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ type: module
33
description: 'A variety of example code for you to learn from and hack upon.'
44
package: Example modules
55
core: 8.x
6+
dependencies:
7+
- toolbar

examples.libraries.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
examples.icons:
2+
version: VERSION
3+
css:
4+
theme:
5+
css/examples.icons.css: {}

examples.module

+86
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,89 @@
2727
/**
2828
* @} End of 'defgroup examples'.
2929
*/
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+
}

field_example/field_example.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ type: module
33
description: An implementation of a field to show the Field API
44
package: Example modules
55
core: 8.x
6+
dependencies:
7+
- examples

images/examples.svg

+56
Loading

js_example/js_example.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ description: 'An example module showing how to use some of the new JavaScript fe
33
type: module
44
package: 'Example modules'
55
core: 8.x
6+
dependencies:
7+
- examples

node_type_example/node_type_example.info.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ package: Example modules
44
type: module
55
core: 8.x
66
dependencies:
7-
-node
7+
- node
8+
- examples

page_example/page_example.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ type: module
33
description: 'An example module showing how to define a page to be displayed at a given URL.'
44
package: Example modules
55
core: 8.x
6+
dependencies:
7+
- examples

phpunit_example/phpunit_example.info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ type: module
33
description: 'How to use PHPUnit-based tests with Drupal 8.'
44
package: Example modules
55
core: 8.x
6+
dependencies:
7+
- examples

simpletest_example/simpletest_example.info.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dependencies:
88
- simpletest
99
- node
1010
- field
11+
- examples

src/Tests/ExamplesTest.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,32 @@ class ExamplesTest extends WebTestBase {
2323
*
2424
* @var array
2525
*/
26-
public static $modules = array('examples');
26+
public static $modules = array('examples', 'toolbar');
2727

2828
/**
2929
* Test whether the module was installed.
3030
*/
3131
public function testExamples() {
32-
$this->assertTrue(\Drupal::moduleHandler()->moduleExists('examples'));
32+
// Verify that the toolbar tab and tray are showing and functioning.
33+
$user = $this->drupalCreateUser(array('access toolbar'));
34+
$this->drupalLogin($user);
35+
36+
// Check for the 'Examples' tab.
37+
$this->drupalGet('/');
38+
$this->assertRaw('<nav class="toolbar-lining clearfix" role="navigation" aria-label="Developer Examples">');
39+
$this->assertText('Examples');
40+
$this->assertNoRaw('<li class="phpunit-example">');
41+
42+
// Install phpunit_example and see if it appears in the toolbar. We use
43+
// phpunit_example because it's very light-weight.
44+
$module_handler = $this->container->get('module_handler');
45+
$module_handler->install(array('phpunit_example'));
46+
// SimpleTest needs for us to reset all the caches.
47+
$this->resetAll();
48+
49+
// Verify that PHPUnit appears in the tray.
50+
$this->drupalGet('/');
51+
$this->assertRaw('<li class="phpunit-example">');
3352
}
3453

3554
}

tour_example/tour_example.info.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ description: 'An example of how to create a tour in Drupal 8.'
44
package: Example modules
55
core: 8.x
66
dependencies:
7+
- examples
78
- tour
89
- toolbar

0 commit comments

Comments
 (0)