Skip to content

Commit 7081996

Browse files
committed
Add admin config form for Patternkit
feat(patternkit.module)
1 parent 964840c commit 7081996

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

include/patternkit_config_form.inc

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Provides the admin settings form for Patternkit.
6+
*/
7+
8+
/**
9+
* Drupal Form API callback for the admin form.
10+
*
11+
* @param array $form
12+
* Drupal Form API form array.
13+
* @param array $form_state
14+
* Drupal Form API form state array.
15+
*
16+
* @return array
17+
* A Drupal Form API admin form array.
18+
*/
19+
function patternkit_config_form(array $form, array &$form_state) {
20+
$libraries = patternkit_pattern_libraries();
21+
$library_options = array();
22+
$library_values = array();
23+
foreach ($libraries as $library) {
24+
$lib_title = $library->getTitle();
25+
$lib_desc = $lib_title;
26+
$lib_metadata = $library->getMetadata();
27+
if (!empty($lib_metadata)) {
28+
$library_values[] = $lib_title;
29+
$lib_desc = t('@title (@count patterns)', array(
30+
'@title' => $lib_title,
31+
'@count' => count($lib_metadata),
32+
));
33+
}
34+
$library_options[$lib_title] = $lib_desc;
35+
}
36+
$form['patternkit_libraries'] = array(
37+
'#type' => 'checkboxes',
38+
'#title' => t('Enabled Patternkit Libraries'),
39+
'#options' => $library_options,
40+
'#default_value' => $library_values,
41+
'#disabled' => TRUE,
42+
);
43+
44+
$form['patternkit_pl_host'] = array(
45+
'#type' => 'textfield',
46+
'#title' => t('PatternLab/Kit REST Services Host'),
47+
'#default_value' => variable_get('patternkit_pl_host',
48+
'http://localhost:9001'),
49+
'#size' => '120',
50+
'#maxlength' => '1023',
51+
);
52+
53+
$form['patternkit_cache_enabled'] = array(
54+
'#type' => 'checkbox',
55+
'#title' => t('Use the Patternkit Library Cache'),
56+
'#default_value' => variable_get('patternkit_cache_enabled', TRUE),
57+
);
58+
59+
$form['patternkit_render_cache'] = array(
60+
'#type' => 'checkbox',
61+
'#title' => t('Use the Patternkit Disk Render Cache'),
62+
'#default_value' => variable_get('patternkit_render_cache', FALSE),
63+
);
64+
65+
$form['patternkit_default_module_ttl'] = array(
66+
'#type' => 'textfield',
67+
'#title' => t('Patternkit Default Pattern TTL (in ms)'),
68+
'#default_value' => variable_get('patternkit_default_module_ttl',
69+
PATTERNKIT_DEFAULT_TTL),
70+
);
71+
72+
$form['#submit'][] = 'patternkit_config_form_submit';
73+
74+
return system_settings_form($form);
75+
}
76+
77+
/**
78+
* Rebuilds Patternkit data on form save.
79+
*
80+
* @param array $form
81+
* Drupal Form API form array.
82+
* @param array $form_state
83+
* Drupal Form API form state array.
84+
*
85+
* @see system_settings_form_submit()
86+
*/
87+
function patternkit_config_form_submit(array $form, array &$form_state) {
88+
if ($form_state['values']['patternkit_cache_enabled']
89+
&& !variable_get('patternkit_cache_enabled', TRUE)) {
90+
$libraries = patternkit_pattern_libraries();
91+
foreach ($libraries as $library) {
92+
$library->getCachedMetadata(NULL, TRUE);
93+
}
94+
}
95+
96+
drupal_set_message(t('Rebuilt Patternkit Library Cache.'));
97+
}

patternkit.module

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// Default TTL is 30 * 24 * 60 * 60, 30 minutes.
99
const PATTERNKIT_DEFAULT_TTL = 2592000;
1010

11+
include __DIR__ . '/include/patternkit_config_form.inc';
12+
1113
/**
1214
* Implements hook_ctools_plugin_directory().
1315
*/
@@ -91,6 +93,21 @@ function patternkit_patternkit_library() {
9193
return $libraries;
9294
}
9395

96+
/**
97+
* Implements hook_menu().
98+
*/
99+
function patternkit_menu() {
100+
$items = array();
101+
$items['admin/config/user-interface/patternkit'] = array(
102+
'title' => 'Patternkit settings',
103+
'description' => 'Configure Patternkit Pattern Library Support.',
104+
'page callback' => 'drupal_get_form',
105+
'page arguments' => array('patternkit_config_form'),
106+
'access arguments' => array('access administration pages'),
107+
);
108+
return $items;
109+
}
110+
94111
/**
95112
* Utility function to get all Patternkit module metadata.
96113
*

0 commit comments

Comments
 (0)