/
plugin_test.module
108 lines (88 loc) · 2.47 KB
/
plugin_test.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Implements hook_menu().
*
* This is just a dummy for testing things faster than unit tests can, because
* unit tests are horrifically slow due to the installer being slow as hell.
*/
function plugin_test_menu() {
$items['plugin'] = array(
'title' => 'Plugin test',
'page callback' => 'plugin_test_page',
'access arguments' => array('access content'),
);
return $items;
}
/**
* Dummy page callback for testing things faster than unit tests can.
*/
function plugin_test_page() {
$plugins = plugin_get_info('fancystring');
$plugin_names = array_keys($plugins);
dpm($plugin_names);
return 'x';
}
/**
* Implements hook_plugin_type_info().
*/
function plugin_test_plugin_type_info() {
$types['fancystring'] = array(
'title' => t('Fancy string mangling'),
'description' => t('Mutate strings in various ways'),
'interface' => 'FancyStringPluginInterface',
'config' => 'FancyStringConfigInterface',
'controller' => 'PluginControllerVariableReuse',
'default' => 'FancyStringDummy',
);
return $types;
}
/**
* Implements hook_plugin_info().
*
* I think we actually deprecated the generic function...
*/
function plugin_test_plugin_fancystring_info() {
$plugins['dummy'] = array(
'title' => t('Dummy'),
'description' => t('Dummy implementation that does nothing.'),
'class' => 'FancyStringDummy',
);
$plugins['rot13'] = array(
'title' => t('ROT 13'),
'description' => t('ROT13 encode a string'),
'class' => 'FancyStringRot13',
);
return $plugins;
}
/**
* Implements hook_plugin_info_alter().
*
* I think we actually deprecated the generic function...
*/
function plugin_test_plugin_info_alter(&$plugins) {
$plugins['rot'] = array(
'title' => t('ROT'),
'description' => t('ROT encode a string to an arbitrary number.'),
'class' => 'FancyStringRot',
'config' => 'FancyStringRotConfig',
);
}
interface FancyStringPluginInterface extends PluginInterface {
public function mutate($string);
}
class FancyStringRot13 extends PluginBaseAbstract implements FancystringPluginInterface {
public function mutate($string) {
return str_rot13($string);
}
}
class FancyStringRot extends PluginBaseAbstract implements FancyStringPluginInterface {
public function mutate($string) {
// @TODO: Implement this.
return $string;
}
}
class FancyStringDummy extends PluginBaseAbstract implements FancyStringPluginInterface {
public function mutate($string) {
return $string;
}
}